Beginners Guide To Using Linux - A Linux command cheat sheet

Welcome to our Learning about Linux guide. Now that you've read Introduction to Linux, lets move forward by showing you a few useful Linux commands.

This sheet uses regular text to distinguish commands from variables which will be shown in green. You will most likely substitute these variables with your own options, flags, user defined files or directories.

 

Getting Help

Command Description
man command Often referred to as the "man page", nearly all commands have an on-line users manual accessible from the command line terminal. These reference manuals list available options, usage examples and general information. We strongly suggest you utilize man and learn more about the command before executing.

Navigation & Directories

Command Description
ls Lists contents of the directory.
pwd Display the directory you're currently in.
cd .. Changes your directory down one level.
cd dir Changes to the directory named 'dir'.
cd / Changes to the root directory. You may also state directories explicitly. Eg: cd /home/username
cd ~ Changes to your home directory.
cd ~- Changes to the last directory you were in.

File Management

Command Description
cp file1 file2 Copies the file named 'file1' to another file called 'file2'. Leaving the original 'file1' intact.
mv file1 file2 Moves (renames) the file 'file1' to 'file2'.
mkdir dir Creates a directory named 'dir'.
rm file Removes the file 'file'.
rm -f dir Removes the directory 'dir' and anything in it.
rmdir foo Removes the directory 'foo'. This only works if the directory is empty.
cat somefile Scroll the contents of the file 'somefile' on your terminal all at once.
cat somefile Displays the contents of 'somefile' on your screen, and lets you scroll through it slowly.
tail somefile Displays the last 10 lines of somefile.

Processes and Programs

Command Description
ps -aux Shows every process that is running on your system and associated process ID.
kill -9 1234 Stops the program process ID '1234' (from ps aux).

Searching

Command Description
whereis something Searches common locations for the program 'something'.
whatis something Use this command if you are unsure what a program does, it should spit out a short synopsis.
grep -R something . Searches for the word 'something' in your current directory.
find / -name something Searches the / dir for 'something'.

The System

Command Description
date Display the current date and time. To adjust system date use: date -s "Thurs Aug 27 14:38:00 EST 2000"
hostname Display the system hostname.
uptime Gives a one line display of time, how long the system has been running, users logged in and load averages.
top Display a sortable listing of running processes and usage in real time.
free -m Information on system memory (in megabytes).
df -h Display information on disks and file systems (in human-readable format).
cat /proc/version Display information on your version of Linux.
cat /proc/cpuinfo Display CPU information on the system.
cat /proc/filesystems Display information on the file system types in use.
uname -a Display information on the kernel version.
shutdown -h now Halts (-h) the system, shutting it down soon as you press enter. You can also specify a time, i.e shutdown -h +15, this means the system will halt in 15 mins.
shutdown -r now Reboots (-r) the system, rebooting it soon as you press enter. You can also specify a time, i.e shutdown -r +15, this means the system will reboot in 15 minutes.

Users and Groups

Command Description
whoami Display who you are currently logged in as.
w Show who is logged on and what they are doing.
last -10 Display a list of the last 10 users logged into the system, alternatively you can specify a username.
useradd To add a new user on your system. See man page for options.
usermod Used to modify a user account. See man page for options.
passwd Change user account password.
userdel -r username To remove a user from your system, along with all files owed by the user.
su - Become superuser (root). Note: sudo is always the better alternative, but requires some configuration.

Additional assistance is available on a wide variety of topics in our Linux How-To's.