Unix Command Line Resources

Unix Command Line help

Commands

Display the manual for command (man <command>)
Navigation (cd <path>)
Display directory Contents (ls -lh <path>)
Show current directory path (pwd)
Clear the terminal screen (clear)
Quit the command line session (exit)
Create a virtual terminal (screen -S <name>)
Check what processes are running (ps fwux)
Terminate a process (kill -HUP <pid>  or   kill -9 <pid>)
List top running processes (top)
Make a command share system resources fairly (nice <command>)
Make an existing process share system resources fairly (renice +<0 to 20> <pid>)
Display file contents (cat <file>)
Display file contents one page at a time (less <file>)
Search for text strings in a file (grep -i <pattern> <file>)
Display the manual for a command

command: man  <command>
description:
* shows the manual page for <command>. This is a great way to learn of the other options and features a command has and also related commands
* adding ‘-k’ searches through all manuals for occurances of the text you enter as <command>

Navigation

command: cd  <path>
description:
* change directory to <path>
* used without <path> will change to your home directory

Display directory contents

command: ls -lh <path>
description:
* shows the contents of directory at <path>
* ‘l’ shows extra details such as permissions, file size and date
* ‘h’ shows the file size in human readable form (in GB, MB, etc)
* used without <path> will show the curent directory

Show current directory path

command: pwd
description:
* prints out the path of the current directory you are in

Clear the terminal screen

command: clear
description:
* clears the text from the termal (pressing ctrl-L does the same)

Quit the command line session

command: exit
description:
* quits the shell session, which may close the terminal window or will disconnect from the remote server if you connected via SSH

Create a virtual terminal

command: screen -S <name>
description:
* creates a virtual terminal session that you can reconnect to later
* (text based) programs can continue to run in the virtual terminal even if you disconnect from the server
* <name> is a unique name to help you identify and reconnect to your screen (you can create multiple screens)
* use screen -rd <name> to reconnect to your screen session (‘r’ is reattach and ‘d’ is detach if still connected elsewhere)
* colour text sometimes does not show up, one workaround is to let screen start the program, such as: screen -S filemanager mc (starts midnight commander and calls the screen ‘filemanager’)

Check what processes are running

command: ps  fwux
description:
* shows your current processes running on the server
* ‘f’ shows a process tree so that you can tell easily which processes are the parents and child processes
* ‘w’  wraps the text output so that you can see the process name and command line options that were specified
* ‘u’ shows username owning the process and some stats
* ‘x’ list all processes owned by you
* adding ‘a’ will show all processes running on the system

Terminate a process

command: kill -HUP <pid>  or  kill -9 <pid>
description:
* Use this command to kill a process that you cannot quit normally. <pid> can be found using the ps command.
* ‘HUP’ sends the hang up signal, the process should try to quit normally
* ‘9’ sends a ‘-KILL’ signal (‘9’ is faster to type), which will forcefully end a process. This is useful if you cannot end a program even with the ‘-HUP’ signal.

List top running processes

command: top
description:
* shows what processes are using the most resources. use ‘q’ to quit; ‘u’ to show a specific username

Make a command share system resources fairly

command: nice <command>
description:
* runs a command with adjusted scheduling so that it does shares resources with other process more fairly

Make an existing process share system resources fairly

command: renice +<0 to 20> <pid>
description:
* allows you to ‘nice’ a process that is already running (make it ‘nicer’)

Display file contents

command: cat <file>
description:
* displays the entire file contents on the screen

Display file contents one page at a time

command: less <file>
description:
* shows the contents of a (text) file one page at a time

Search for text strings in a file

command: grep -i <pattern> <file>
description:
* search through <file> for <pattern>, matched lines will be displayed
* ‘i’ means ignore case (match upper or lower characters)