Getting Familiar with the Linux Command Line

Written by Mark Sanborn: Sep 25, 2007

Navigating and Moving Files Around

The first thing you need to know about navigation the unix world is the difference between ‘/textFile.txt’ and ‘textFile.txt’. Notice the ‘/’ in front of the first example. This means start at the root directory and look for textFile.txt. Where the later example says look in the current directory for textFile.txt. Users comming from windows might recognize the root directory as c:/ where the current directory might be ‘Documents and Settings’ or /home/username/docs/.

pwd - Print working directory This command is useless if you Customize your PS1 to include the pwd command. Example: pwd Output: /home/username/ Explanation: This will tell you what directory you are currently in.

ls - List the directory Example: ls Explanation: This will show you the contents of non-hidden files and directories in your working path (see the command above)

Example: ls -a Explanation: This will show you the contents of ALL files and directories in your working path.

cd - Change directory Example: cd /var/log Example: cd .. (brings you to /var) Explanation: Move up, down, or to a completely new directory

cp - Copy Example: cp /etc/SomeConfigFile.txt /home/username/SomeConfigFile.html Explanation: This will copy the file ‘SomeConfigFile.txt’ in the directory /etc and place it in the directory /home/username while renaming it to include an html extention.

mv - Move / Rename Example: mv /home/username/MyPic.jpg /home/username/vacation/Mypic.jpg Explanation: This is like cutting and pasting a file in windows. This is cutting the file MyPic and pasting it into the folder /home/username/vacation/Mypic.jpg

Example: mv /home/username/MyPic.jpg /home/username/Mypic092507.jpg Explanation: This will rename the file MyPic.jpg to include the date, Mypic092507.jpg.

rm - Remove / Delete Example rm /home/username/oldfile.txt Explanation: this will delete the file name oldfile.txt in the directory /home/username

Example rm -R /home/mark/temp Explanation: This will delete the folder temp. The -R flag tells rm to include subdirectories

Example: rm * /home/mark/temporaryFiles Explanation: You can include wild cards as well. This command will delete all files in the folder temporaryFiles

File Permissions

chmod - Change file permissions Example: chmod -R 755 vacation Explanation: Recursively (go into subdirectories) change permissions to the default on the directory vacation.

chown - Change owner Example: chmod mark vacation Explanation: Change owner on directory vacation to mark.

Compressing and Extracting

Compressing Example: tar -cvjf test.tar.bz2 test.txt Explanation: Compress the file test.txt with the bz2 compression.

Extracting Example: tar -xvjf test.tar.bz2 Explanation: This will extract the file test.tar.bz2 to the current directory.

Text Maniuplation and Pipe

history - List of recent commands you have used Example: history

grep - Find a keyword and output the results Example: history | grep nano Explanation: This command prints the results of the command history and ‘|’ (pipes) them to the program grep. grep then searches through the results and only returns the lines of results that contain the keyword ‘nano’. This specific example will look through the recent text files you have edited with the program nano.

cat - Concatenate Example: cat /proc/acpi/thermal_zone/THRM/temperature Explanation: Concatenate (Print) your CPU temperature to the screen.

less - Show only what you can see on your screen at a time Example: cat dmesg | less Explanation: Show the dmesg file piece by piece.

tail - Show the last bit of the text file Example: cat dmesg | tail Explanation: Show the the last part of the file that will fit on your screen.

slocate - Search your hard drive for files matching a specific keyword Example: slocate Xorg.conf Explanation: Find where the file Xorg.conf is located at.

Example: updatedb Explanation: Update the hard drive index for searching with slocate.


reboot - Reboot the computer

halt - Shutdown the computer

top - See system resources and currently running programs

ps -A - See a list of programs that are running Example: ps -A | grep gnome Explanation: Find any programs running that have gnome in their name. (See grep)

df - Show remaining disk space

du -sh directoryName/ - Show the size of a directory in human readable format (hence the h flag)

uptime - Display the system uptime


ifconfig - Interface Configuration Example: ifconfig eth0 down Explanation: Deactivate your primary ethernet card.

scp - Shell copy Example: scp root@ . Explanation: Copies the file Mypic remote from the host 192.168.101 via ssh to current directory.

wget - Web get Example: wget Explanation: Download Ubuntu to the current directory.


md5 - Do a md5 hash on a file Example: md5 filename.txt Explanation This will run an md5 hash on the file this will output a 32 digit hex like this, ‘ffd93f16876049265fbaef4da268dd0e’.


Example: mplayer videoyouwant.avi -vo aa Explanation: Watch your favorite avi file in ASCII format.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.