An Introduction to Linux Command Line Absolute Basics

Be sure to review the commands below and feel free to give them a try on your system. You can download this blog as a PDF for further review here.

arch

Outputs the processor architecture.

$ arch

i686

cat

Outputs the contents of a file.

$ cat lorem.txt

cd

Change the working directory.

$ cd /bin

cp

Copies a file.

$ cp lorem.txt copy_of_lorem.txt

date

Outputs the current date and time.

$ date

Sat Mar 3 12:07:09 GMT 2007

df

Reports the amount of disk space used and available on filesystems.

$ df

Filesystem 1K-blocks Used Available Use% Mounted on<br>
/dev/simfs 39845888 218048 39627840 1% /

dir

List directory contents.

$ dir

copy_of_lorem.txt lorem.txt moo.txt www

duEstimate file space usage.

$ du -h /bin

7.8M /bin

echo

Display a line of text.

$ echo foobar

foobar

exit

Cause the shell to exit.

$ exit

free

Display amount of free and used memory in the system.

$ free

total used free shared buffers cached
Mem: 8299892 8287708 12184 0 2641772 1731236
Low: 3581300 3572764 8536
High: 4718592 4714944 3648
-/+ buffers/cache: 3914700 4385192
Swap: 8193140 2335664 5857476

headOutput the first part of files.

$ head -2 lorem.txt

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim

hostname

Outputs the machines hostname on the network.

$ hostname

anapnea.net

id

Outputs user id, group id, and groups of your account.

$ id

uid=1478(smallfoot) gid=100(users) groups=35(games),100(users)

lastShow listing of last logged in users.

$ last -n 3

alice pts/6 192.0.34.166 Fri May 18 16:17 still logged in
bob pts/2 64.233.183.103 Fri May 18 16:17 still logged in
clare pts/6 72.5.124.61 Fri May 18 15:54 - 15:55 (00:01)

lognamePrint user’s login name.

$ logname

smallfoot

ls

List directory contents.

$ ls

copy_of_lorem.txt lorem.txt moo.txt www

manOpens the manual page for a software or function.

$ man bash

The man pages are the first place to go when you’re looking for help. The man command gives access to your computer’s online documentation (manuals… get it?). If you need to see additional arguments for uname, for instance, open a terminal and type man uname. The man page will give you a basic run down on how to use the command, what package it is bundled with, and sometimes cross-references similar commands that may be useful.

mkdirMakes a directory.

$ mkdir foobar

mv

Moves a file.

$ mv lorem.txt ipsum.txt

pidof

Find the process ID of a running program.

$ pidof fetchmail

22392

ping

Pings a host.

$ ping -c 2 127.0.0.1

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.052 ms

— 127.0.0.1 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.048/0.050/0.052/0.002 ms

ps

Outputs running processes.

$ ps

PID TTY TIME CMD
21542 pts/12 00:00:00 bash
27706 pts/12 00:00:00 ps

pstree

Display a tree of processes.

$ pstree

init-+-2*[BitchX]
|-3*[bash—sleep]
|-fetchmail
|-screen-+-bash—irssi
| `-bash—ctorrent
|-screen-+-bash—lisp.run
| |-bash—vi
| |-2*[bash]
| `-bash—lynx
|-2*[screen—bash—irssi]
|-screen—irssi
|-screen—bash
|-screen-+-bash
| `-irssi
|-skjerm—irssi
|-sshd-+-5*[sshd—sshd—bash—irssi]
| |-8*[sshd—sshd—bash]
| |-sshd—sshd—bash—screen
| |-sshd—sshd
| `-sshd—sshd—bash—pstree
`-syslog-ng

pwd

Outputs the name of current working directory.

$ pwd

/home/smallfoot

rm

Removes a file or directory.

$ rm lorem.txt

rmdir

Removes a directory.

$ rmdir foobar

size

List section sizes and total size.

$ size /bin/bash

text data bss dec hex filename
621233 22712 19176 663121 a1e51 /bin/bash

stat

Outputs file status.

$ stat lorem.txt

File: `lorem.txt’
Size: 453 Blocks: 8 IO Block: 4096 regular file
Device: 77h/119d Inode: 27312217 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 1478/smallfoot) Gid: ( 100/ users)
Access: 2007-03-03 12:24:39.000000000 +0000
Modify: 2007-03-03 12:24:39.000000000 +0000
Change: 2007-03-03 12:24:39.000000000 +0000

tailOutput the last part of files.

$ tail -2 lorem.txt

occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.

touchChange a file’s access and modification timestamps. If file does not exist, create it.

$ touch lorem.txt

uptimeOutputs the system uptime.

$ uptime

14:50:26 up 7 days, 17:52, 18 users, load average: 0.08, 0.02, 0.01

wShow who is logged on and what they are doing.

$ w

12:14:30 up 5 days, 15:16, 19 users, load average: 0.00, 0.00, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
charlie pts/0 Fri21 3:26m 2.52s 2.52s irssi
alice pts/2 Wed17 30:21m 0.00s 0.00s -bash
emma pts/4 11:37 36:57 0.00s 0.00s -bash
frank pts/5 11:48 11:03 0.00s 0.00s -bash
smallfoo pts/12 12:01 0.00s 0.04s 0.01s w

wcCounts lines in a file.

$ wc -l lorem.txt

7 lorem.txt

whatis

Search the whatis database for complete words.

$ whatis bash

bash (1) - GNU Bourne-Again SHell
bash [builtins] (1) - bash built-in commands, see bash(1)

who

Outputs who is currently logged into the system.

$ who

charlie pts/0 Mar 2 21:37 (xtreme-11-65.acme.com)
alice pts/2 Feb 28 17:48 (147.21.16.3)
emma pts/4 Mar 3 11:37 (32.84-48-181.uac.com)
frank pts/5 Mar 3 11:48 (port-212-202-233-2.foobar.org)
smallfoot pts/12 Mar 3 12:01 (c-12776f4.cust.example.net)

whereis

Locate the binary, source, and manual page files for a command.

$ whereis bash

bash: /bin/bash /etc/bash /usr/share/man/man1/bash.1.gz

whoami

Outputs your username / the name of your account.

$ whoami

username


Related Posts

Tags: ,

One Response to “An Introduction to Linux Command Line Absolute Basics”

  1. Daniel Craig Says:

    Hey, I was looking around for a while searching for introduction to network security and I happened upon this site and your post regarding An Introduction to Linux Command Line Absolute Basics, I will definitely this to my introduction to network security bookmarks!

Leave a Reply