Easy Command-Line Introduction

Posted: 9 Feb 2005

Among the many wonders of Linux is the ability to customize how you, individually, like to do things. Many people like the ability to use the mouse to point and click on a graphical interface. This is to say, they like to use a window manager like Gnome or KDE. Another option, however, is to use the command line. Contrary to popular belief, the command line is not difficult to use. In some cases, it takes the complication out of things. I'd like to run through a bunch of common commands. We'll look at what each does and how to use each one.

Find the TERMINAL PROGRAM icon in your Kicker bar and click on it:

This opens your terminal window so you can try these babies out. Also, after you type each command, press the ENTER key to run it. Here is a list of the common commands:

Command: ls

Usage: ls

Explanation: Displays contents of the current directory.

Sample Output:

[1702][smorris@linux:~/home]$ ls
bin  Desktop  Documents  hardware.txt  icons.lst  public_html
[1702][smorris@linux:~/home]$

Command: mkdir

Usage: mkdir <dirname>

Explanation: Makes a subdirectory in the current directory.

Sample Output:

[1702][smorris@linux:~/home]$ mkdir temp
[1808][smorris@linux:~/home]$

Command: rmdir

Usage: rmdir <directory>

Explanation: Removes a directory.

Sample Output:

[1834][smorris@linux:~]$ rmdir temp
[1834][smorris@linux:~]$ 

Command: cd

Usage: cd <new directory>

Explanation: Changes the current directory to a new one.

Sample Output:

[1834][smorris@linux:~]$ cd home
[1834][smorris@linux:~/home]$

Command: pwd

Usage: pwd

Explanation: Shows the present working directory.

Sample Output:

[1808][smorris@linux:~/home]$ pwd
/home/smorris/home
[1825][smorris@linux:~/home]$

Command: cp

Usage: cp <source file> <target file>

Explanation: Copies a file from its current location to somewhere else.

Sample Output:

[1938][smorris@linux:~/home]$ cp hardware.txt mystuff.txt
[1938][smorris@linux:~/home]$

Command: mv

Usage: mv <source file> <target file>

Explanation: Moves a file from its current location to somewhere else.

Sample Output:

[1938][smorris@linux:~/home]$ mv hardware.txt mystuff.txt
[1938][smorris@linux:~/home]$

Command: rm

Usage: rm <filename>

Explanation: Removes a file.

Sample Output:

[1938][smorris@linux:~/home]$ rm mystuff.txt
[1939][smorris@linux:~/home]$

Note: The result of the 'rm' command is permanent. You cannot undo it, so be very careful with this command.

Command: ps

Usage: ps aux

Explanation: Shows a list of the current running processes.

Sample Output:

[1839][smorris@linux:~]$ ps aux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   596   80 ?        S    Jan27   0:01 init [5]
root         3  0.0  0.0     0    0 ?        S    Jan27   0:02 [events/0]
root         4  0.0  0.0     0    0 ?        S    Jan27   0:00 [khelper]
root         5  0.0  0.0     0    0 ?        S    Jan27   0:00 [netlink/0]
root         6  0.0  0.0     0    0 ?        S    Jan27   0:00 [kacpid]
root        23  0.0  0.0     0    0 ?        S    Jan27   0:19 [kblockd/0]
root        36  0.0  0.0     0    0 ?        S    Jan27   0:00 [aio/0]
root        35  0.0  0.0     0    0 ?        S    Jan27   0:12 [kswapd0]
root       618  0.0  0.0     0    0 ?        S    Jan27   0:00 [kseriod]
root      1643  0.0  0.0     0    0 ?        S    Jan27   0:00 [ata/0]
root      1645  0.0  0.0     0    0 ?        S    Jan27   0:00 [scsi_eh_0]
root      1646  0.0  0.0     0    0 ?        S    Jan27   0:00 [scsi_eh_1]
root      1655  0.0  0.0     0    0 ?        S    Jan27   0:02 [reiserfs/0]
root      2168  0.0  0.0     0    0 ?        S    Jan27   0:00 [khubd]
root      2224  0.0  0.0  1360  256 ?        S    Jan27   0:00 udevd
root      2484  0.0  0.0  1432  320 ?        S    Jan27   0:00 [hwscand]
smorris  14651  0.0  0.3  4248 1840 pts/3    Ss   18:39   0:00 /bin/bash
smorris  14661  0.0  0.1  2372  704 pts/3    R+   18:39   0:00 ps aux
[1839][smorris@linux:~]$

Note: You will see much more output than this. I had to cut it off because it was too long to put all of it here.

Command: kill

Usage: kill <process id>

Explanation: Terminates a process.

Sample Output:

[1848][smorris@linux:~]$ kill 14988
[1848][smorris@linux:~]$ 

Note: The process ID can be found using the 'ps' command, above.

Command: uptime

Usage: uptime

Explanation: Shows how long it has been since the computer was last rebooted.

Sample Output:

[1848][smorris@linux:~]$ uptime
  6:54pm  up 11 days 21:36,  4 users,  load average: 0.10, 0.14, 0.10
[1854][smorris@linux:~]$

Command: date

Usage: date

Explanation: Shows the current system time and date.

Sample Output:

[1854][smorris@linux:~]$ date
Tue Feb  8 19:20:07 CST 2005
[1920][smorris@linux:~]$

Command: ifconfig

Usage: /sbin/ifconfig

Explanation: Shows your IP address and network adapter information.

Sample Output:

[1825][smorris@linux:~/home]$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0B:DB:C5:E1:AC
          inet addr:192.168.0.106  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20b:dbff:fec5:e1ac/64 Scope:Link
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2911835 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1878982 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2017894151 (1924.4 Mb)  TX bytes:199806447 (190.5 Mb)
          Base address:0xdf40 Memory:feae0000-feb00000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2499998 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2499998 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:584776793 (557.6 Mb)  TX bytes:584776793 (557.6 Mb)

[1827][smorris@linux:~/home]$

Note: Look at the second line. After the 'inet addr:' there is a group of numbers and periods. This is the IP address. In this example, the IP address is 192.168.0.106.

Command: ping

Usage: ping <host or ip>

Explanation: Sends a small signal to a remote server, which answers. This is very useful for testing an Internet connection.

Sample Output:

[1827][smorris@linux:~/home]$ ping google.com
PING google.com (216.239.39.99) 56(84) bytes of data.
64 bytes from 216.239.39.99: icmp_seq=1 ttl=239 time=32.1 ms
64 bytes from 216.239.39.99: icmp_seq=2 ttl=239 time=32.4 ms
64 bytes from 216.239.39.99: icmp_seq=3 ttl=239 time=33.0 ms
64 bytes from 216.239.39.99: icmp_seq=4 ttl=239 time=33.5 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 32.103/32.792/33.556/0.577 ms
[1832][smorris@linux:~/home]$

Note: To stop the pinging, press CTRL+C.

Command: top

Usage: top

Explanation: Displays a report of the currently running processes. This report updates every 3 seconds.

Sample Output:

top - 18:45:24 up 11 days, 21:27,  4 users,  load average: 0.11, 0.07, 0.08
Tasks: 121 total,   2 running, 119 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.6% us,  0.8% sy,  0.0% ni, 94.8% id,  1.5% wa,  0.3% hi,  0.0% si
Mem:    514496k total,   509096k used,     5400k free,    75768k buffers
Swap:  1959920k total,   277912k used,  1682008k free,   143512k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
17509 root      16   0  204m  56m 146m R  1.7 11.3  21:33.88 X
13480 smorris   16   0 36696  23m  29m S  0.7  4.6   0:12.08 kate
14650 smorris   15   0 30364  14m  26m S  0.2  2.9   0:00.62 konsole
17647 smorris   16   0 50016  26m  34m S  0.1  5.3   2:25.75 kicker
 8616 smorris   15   0 66588  38m  32m S  0.1  7.6   0:33.73 firefox-bin
 8371 lp        16   0  6876 1420 3740 S  0.0  0.3   1:54.78 cupsd
17640 smorris   15   0 27720  12m  24m S  0.0  2.4   0:44.25 kwin
17644 smorris   15   0 25440 9648  23m S  0.0  1.9   0:03.80 khotkeys
    1 root      16   0   596   80  452 S  0.0  0.0   0:01.33 init
    2 root      34  19     0    0    0 S  0.0  0.0   0:04.60 ksoftirqd/0
    3 root       5 -10     0    0    0 S  0.0  0.0   0:02.77 events/0
    4 root       5 -10     0    0    0 S  0.0  0.0   0:00.02 khelper
    5 root       5 -10     0    0    0 S  0.0  0.0   0:00.06 netlink/0
    6 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 kacpid
   23 root       5 -10     0    0    0 S  0.0  0.0   0:19.39 kblockd/0
   36 root       6 -10     0    0    0 S  0.0  0.0   0:00.00 aio/0
   35 root      15   0     0    0    0 S  0.0  0.0   0:12.40 kswapd0
  618 root      24   0     0    0    0 S  0.0  0.0   0:00.00 kseriod
 1643 root       6 -10     0    0    0 S  0.0  0.0   0:00.00 ata/0

Note: Press SHIFT+M to sort by memory. Press SHIFT+P to sort by CPU usage. Press CTRL+C to exit.

There are many, many commands that I could have listed here. These are some of the basic everyday ones. For a more in-depth look at using the command line, there are many tutorial sites available, such as this one.



Informacja z serwisu http://www.djack.com.pl