What is UNIX?
UNIX is an operating system which was first developed in the 1960s.
It is a stable, multi-user, multi-tasking system for servers, desktops and laptops.
Types of UNIX
There are many different versions of UNIX, although they share common similarities. The most popular varieties of UNIX are Sun
Solaris, GNU/Linux, and MacOS X.
The UNIX operating system
The UNIX operating system is made up of three parts; the kernel, the shell and the programs.
Kernel: The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the file store
and communications in response to system calls.
Shell: The shell acts as an interface between the user and the kernel.
Lists files in current directory.
Gives a "long listing" of the files in current directory.
List all files including hidden files.
Recursively list contents of sub-folders.
List one file or folder per line and separate content by commas.
list the contents with modification time descending order
List the contents in reverse order based on time.
List the contents ordered by size ascending.
List the contents in reverse order by size.
cat filename [-n] [-b] [-u] [-s] [-v]
cat [file.txt] [file2.txt] > [file3.txt]
Allows look, modifying or combining a file.
Reads file1.txt and file2.txt and combines those files to make file3.txt.
cut [-b] [-c] [-f] list [-n] [-d delim]
cut –b [file.txt]
To extract parts of each line of a file.
cut –c [file.txt]
The list following -b specifies byte positions (for instance, -b1-72 would pass the
first 72 bytes of each line).
The list following -c specifies character positions (for instance, -c1-72 would pass
the first 72 characters of each line).
sort [options] [file]
sort –r [file.txt]
sort –n [file.txt]
sort –u [file.txt]
Sorts the lines in a text file.
Sort the file, file.txt in reverse order.
Pick unique lines in a file and then sort them.
uniq [-c | -d | -u ] [ -f fields ] [ -s
char ] [-n] [+m] [input_file] [
uniq –i [file.txt]
uniq –c [file.txt]
uniq –u [file.txt]
uniq –d [file.txt]
Report or filter out repeated lines in a file.
grep [options] PATTERN [file]
grep "one" file.txt
grep -i "one" file.txt
grep "one * two" file.txt
Finds text within a file.
Search file.txt in the current directory for any reference of one.
use wildcard * (asterisk).
Identify case-insensitive unique lines.
Get count of unique lines.
Get only unique lines from a file.
Get all duplicate lines from a file.
df [OPTION] [FILE]
List all the file systems on the system, their mount points and their total size, free
size and used size.
Displays the sizes in an easy to read format.
Display type of file-system
Display size of file systems in specified units
du [-a] [-k] [-s] [-d] [-L] [-o] [-r] [x] directories
du –h test
Tells you how much space a file occupies.
ps [-a] [-A] [-c] [-d] [-e] [-f] [-j] [l] [-L] [-P] [-y] [ -g grplist ] [ -n
namelist ] [-o format ] [ -p
proclist ] [ -s sidlist ] [ -t term] [ u uidlist ] [ -U uidlist ] [ -G
ps –e | head –n3
Displays the list of all processes that the system's processor is currently handling.
kill [-s] [-l] [pid]
kill -9 [pid]
It will kill or stop running processes.
To forcefully kill a process.
To kill processes by name
split [-linecount | -l linecount ] [
-a suffixlength ] [filename]
split –l1000 file.txt
split –b5m file.txt
Split a file into pieces.
Display human-readable size for files/folders listed by 'du'
Display all running processes
Display processes based on process id
Display multiple processes by process ids
To split a file based on number of lines.
to split a file based on size of data
chmod 111 a.txt
chmod 222 a.txt
Changes the permission of a file. There are 3 types of permissions for a file i.e. read,
write and execute abbreviated as r, w and x respectively. This command also
assigns numbers 4, 2 and 1 to read, write and execute permissions respectively.
These 3 permissions can be separately set for three types owner, group, everyone
crontab [-u user] file
It’s used to schedule scripts to run periodically at configured times.
To display jobs scheduled in crontab.
To add, update or delete jobs from crontab.
To delete all scheduled jobs from crontab.
Finds one or more files assuming that you know their approximate filenames.
List contents of current folder using 'find' comamnd
cp a.txt b.txt
cp a.txt newdir(/home/)
It’s used to create copies of files and folders.
To copy a file in same directory.
To copy a file in different directory.
mv [-f] [-i] oldname newname
mv a.txt b.txt
mv a.txt subdir (/home/)
mv subdir copydir
It’s used to move files/folders from one folder to another.
To move a file to another file.
To move a file to another folder.
to move a folder.
chmod [OPTION] [MODE]
rm [-f] [-i] [-R] [-r] [filenames |
rm –f file.txt
rm –rf subdir
It’s used to delete files and folders.
mkdir [option] directory
mkdir –p subdirA/sundirB
To create a new directory.
To make a folder.
To make a folder and sub-folders hierarchy.
unzip –l first.zip
To compress files/folders to a smaller size. Zipping a file helps save disk space
while storing or helps conserve network bandwidth while transporting the file.
It’s used to extract the files/folders from a zipped file.
tar -cvwf file.tar myfile.txt
tar -xvwf myfile.tar
Create Tape ARchives (TAR) and add or extract files.
Creating a tar file.
Extracting the files from a tar file.
tail -n2 basic.txt
tail -f error.log
It will display the last n lines or last n bytes from a byte. It can also monitor a file.
To display last n lines of a file.
To use option -f to track changes to a file.
paste [-s] [-d list] file
It’s used to merge multiple files together.
To delete a file.
To delete a file without prompting.
To delete a folder.