$man <command>
Displays the on-line manual pages for the command
$clear
Clears the terminal screen
$pwd
Returns the working directory name
$echo <string>
Writes the string to the standard output
$printf <string>
Format and print the string Example: print $PATH $printf “%s\n” $PATH
$uptime
Show how long system has been running
$which <program>
Locate a program file in the user’s path
$whereis <program>
Checks the standard binary directories for the specified programs, printing out the
FILES
$cd [directory]
Change directory Commonly used directory symbols:
$ls
$ls -a : Show hidden files
$ls -l : Show long list
$ls -1 : Show just the filename per line
$ls -h : Human readable format
$file Determine file type (e.g. gzip)
READING FILES
$more
Display content of a file one screen at a time
spacebar : Scroll to next screen; b=previous screen
enter : Scroll one line
h : Help for more
q : Quit help
$less <file>
Less is a program similar to more, but which allows backward movement in the file as well as forward movement
$cat <file>
Reads files sequentially, writing them to the standard output
$head [-number] <file>
Display first lines of a file
$tail [-number] <file>
Displays the contents of file or, by default, its standard input, to the standard output
$touch <file>
Sets the modification and access times of files. If any file does not exist, it is created with default permissions
$tee <file>
Copies standard input to standard output. Press ctrl-d to stop adding content
$mkdir <directory>
Create a directory
$wc
Display the number of lines, words, and bytes contained in each input file, or standard input
$diff <file1> <file2>
Compare two files line by line. Will print only the different lines.
$locate <file>
Locate files on disk
$find <path> <expression> <action>
Search for files by name or content
$rm <file or directory>
Delete <file or directory>
Example: Delete the and it’s content $rm -r
$mv <source_file> <target_file>
Renames a file
$mv <source_file> <target_directory>
Moves a file
Example: move directory up in hierarchy $mv ..
$cp
Copy a file/directory within the same machine (Use scp command to copy to a remote machine)
Example: Copy and rename a file
$cp <file_name> <new_file_name>
Example: Copy to directory
$cp <file_name> <directory_name>
Example: Copy and rename a directory
$cp -R <directory> <new_directory>
Example: Copy all files of specific type to a directory
$cp *.txt <directory>
$ln -s <file> <link name>
Create an alias (link) to a file
$sort <file>
Sort the content of a file -r reverse sorts -n numeric sort
Example: sort the and write the result to sorted.txt $sort | uniq -u > sorted.txt
$uniq [-ucd] filename(s)
Looks for duplicate lines. Data must be sorted first
$grep <pattern> <file_name>
Prints lines that contain a match for a pattern.
$tr “string1” [“string 2”]
Search and replace tool. tr only accepts its input from pipes and redirections. it doesn’t accept files as input.
Example: Print a.txt to screen after deleting all occurences of “;” $cat a.txt | tr -d “;”
Example: $echo “SSSS SS” | tr -s “S” “S”
$tar
Creates and manipulates streaming archive files. This implementation can extract from tar, pax, cpio, zip, jar, ar, and ISO images and can create tar, pax, cpio, ar, and shar archives.
DISK USAGE
$du [file or directory]
Display the file system block usage for each file or directory. If no file/directory is specified, the block usage of the current directory is displayed.
$df
Display free disk space
REDIRECTIONS & PIPES
> Redirect standard output. Dont overwrite file if it exists
>! Redirect standard output. Overwrite file if it exists
>& Redirect standard output and standard error
Example: Redirect command output into a file
$ls > result.txt
Use > /dev/null file to dispose of errors message
Example: Find a file named my_file_name and print the result to ~/find.txt; Hide errors (e.g. “permissions denied”)
$find / -name my_file_name.* > /dev/null > ~/find.txt
< Redirect standard input
>> Append standard output <command> >> : Append output to the end of an existing
<command> < : Redirect input to a command from a file
| Redirect standard output to another command (pipe)
Example: Show paginated details of running processes
$ps -ex | more
| : Pipe output of command1 to be the input of command2 (If an output file is desired in the middle of a pipe use the tee command)
Example: Count the number of connected users
$who | wc -l
PROCESSES
$ps
Show active processes
Example: Find processes by name $grep -l <process_name_regex>
$kill [-signal] pid
Kill a process.
Some of the more commonly used signals:
$top
Display and update sorted information about processes See man pages for list of possible keys. common keys are: cpu, threads, ports
$htop
Display and update sorted information about processes
USER & PERMISSIONS
$sudo <command>
Execute the command as a super user
$su
(substitute user) opens a session as an admin
$exit
Exit root
$whoami
Display effective user id
$who
Print all connected user names
$passwd
Change password
$chmod <who> <operation> <permissions> <file or directory name>
Change owner/group access to a file or directory
Who: u user; g group; o other; a all above
Operation: + add; - remove; = set (meaning reset to nothing and set only what was specified)
Permissions: r w x
Example: Adds read/execute permissions to group
$chmod g +rx <file>
Example:
$chmod 743 <file>
Note that to $cd into a directory you need the x permissions