List Of All Unix Commands With Examples Pdf
- Common Unix Commands Pdf
- List Of All Unix Commands With Examples Pdf Example
- List Of All Unix Commands With Examples Pdf File
- Basic Unix Commands With Examples
Logname: Logname command is used to display the login name of the user. Example: $Logname. Are required between commands and options and between options and each argument. Commands must be typed in the proper case (nearly always lower case). Although each option to a command may be pre xed by a -', with almost all of the standard commands you may put the options together. For example command -a -b -c -d can often be abbreviated as.
- Example UNIX commands.ls stands for list. This command lists the contents of the current location.pwdstands for print working directory. This command tells you your current location in the shell.hostname gives you the name of the host that the shell resides on.who lists all the users currently logged into the server.
- List of basic unix commands with examples pdf There are many more options, for example to list files by size, by date.following example files from the LATEX training page. For more information on UNIX commands, see Using LaTeX on UNIX Systems. Pdf of unix commands with examples Examples: Solaris, OpenSolaris, Irix, AIX, HP-UX, OS X, Linux, FreeBSD.
- UNIX COMMANDS CHEAT SHEET Command Example Description 1. Ls ls ls -alF Lists files in current directory List in long format 2. Cd cd tempdir cd. Cd dhyatt/web-docs Change directory to tempdir Move back one directory Move into dhyatt's web-docs directory 3. Mkdir mkdir graphics Make a directory called graphics 4. Cp cp file1 web-docs.
- Nov 08, 2010 This article provides practical examples for 50 most frequently used commands in Linux / UNIX. This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands.
Various useful unix-commands are listed in this chapter. Also, some of the examples of these commands are shown in the last section. Further, in next chapter, shell-scripting is discussed.
1.1. Unix commands cheatsheet¶
Following are the list of various useful unix-commands,
1.1.1. Basic file commands¶
Commands | Details |
---|---|
Basic opeations | |
ls | directory listing |
ls -a | show hidden file |
ls -l | show details for file |
ln file1 file2 | create file2 (linked with file1). Changes will appear in both file |
ln -s file1 file2 | create shortcut of file1 as file2 (soft link) |
mkdir dirname | create directory dirname |
cd dirname | go to dirname |
cd | go to home directory |
pwd | present working directory |
rm filename | remove (delete) filename |
rm -r dirname | remove directory dirname |
rm -f filename | Force remove file filename |
rm -rf dirname | Force remove directory dirname |
cp file1 file2 | copy file1 to file2 |
cp -r dir1 dir2 | copy dir1 to dir2 |
mv file1 file2 | rename file1 to file2 |
touch filename | create filename (if not exist) |
cat > filename | add content to file (ctrl-c to exit) |
cat >> filename | add content at the end of the filename |
cat filename | show content of filename (all at once) |
more filename | show content of filename (fit to screen with more option) |
head filename | show first 10 lines of filename |
tail filename | show last 10 lines of filename |
tail -f filename | last 10 lines of the filename (useful for log files) |
command > filename | write output of command in the filename (overwrite the fie |
command >> filname | append the output at the end of file name |
wc filename (wc -l, -w, -c) | returns number of lines, word, character and filename. |
chmod 777 filename | read(4), write(2) and execute(1) permission to all [4+2+1=7] chmod [owner, group, others] filename |
1.1.2. Sort¶
Commands | Details |
---|---|
Sort | |
sort filename | sort the lines of the filename |
sort -u filename | sort and eliminate duplicates |
sort -r filename | reverse order sort |
sort file1 -o file2 sort file1 > file2 | sort data of file1 and save to file2 |
sort -n filename | sort data based on numeric value i.e. 12 > 4 |
sort -M fielname | sort data with month name i.e. Jan, Feb, Mar etc. |
1.1.3. Cut¶
Commands | Details |
---|---|
Cut | |
cut d”-” 1,4 filename | cut the 1st and 4th column of filename, where - is delimiter |
cut -c3- filename | remove first 2 character from each line and printed the rest |
cut -c-3-8 filename | print character 3-8 from each line |
cut -c1-3,6-8,10- filename | print character 1-3, skip 4, print 6-8, skip 9, print 10 to end from each line |
cut -d’,’ -f3 filename | extact field-3 from each line with ‘,’ as delimiter |
cut -d’,’ -f3,6 filename | extact field-3-to-6 from each line with ‘,’ as delimiter |
1.1.4. Paste¶
Commands | Details |
---|---|
Paste | |
paste file1 file2 file3 | paste the lines of file2, then file3 beside the lines of file1 |
paste -d’,’ file1 file2 | put comma at the end of each file content |
paste -s filename | merge all lines of filename |
1.1.5. Grep¶
Commands | Details |
---|---|
grep | |
grep pattern filenames | print the lines with pattern in filenames |
grep ‘[0-9]’ filenames | print the lines from filenames which have numbers 0-9 (regular expression) |
grep -v pattern filenames | print all lines which do not contain pattern |
grep -l pattern filenames | print the filenames which have pattern |
grep -n pattern filenames | print the line numbers as well |
1.1.6. Sed¶
Commands | Details |
---|---|
sed | |
sed ‘s/word1/word2/’ filename | replace word1 with word2 in filename |
sed ‘s/word1/word2/’ file1 > file2 mv file2 > file1 | use two steps to make change permanent |
sed -n ‘2,4p’ filename | print line 2 to 4 of filename |
sed -n /word1/p’ filename | print lines which contain word1 in filename |
1.2. Multiple commands¶
1.2.1. Pipes¶
Pipes are used for sending output of one command to next command.
1.2.2. Run individual commands (;)¶
Commands can be run separately from one line by separating them using semicolon,
1.3. Examples¶
1.3.1. File examples¶
1.3.2. Sort example¶
1.3.3. Cut command¶
30 Basic UNIX Commands List With Examples is a good reference for someone who is beginner to UNIX/LINUX Operating System. These are most commonly used and basic Unix commands listed below:
- Man (Help Command)
man is the interface used to view the system’s reference manuals. it can be used to display manual pages, scroll up and down, search for occurrences of specific text, and other useful functions.
Example 1:
man cat
This command will show you the manual page for the cat command, like syntax and the usage of the cat command.
Example 2:
man -k search
This command can be used to search for the text “search” in all manual pages
2. cat
cat command is used to concatenate or displays the contents of a file.
Displaying the contents of file:
cat filename
— Displays the content of filename
Displaying the contents of file (including special characters):
cat –v filename
— Displays the content of filename including special characters like, control characters.
Displaying the contents of file with line numbers:
cat –n filename
— Displays the content of filename with the line numbers at the beginning.
Copy file content to new File:
Cat filename1 > filename2
— filename1 content is copied to filename2(filename2 is truncated before copying)
Appending one file content to another:
cat filename1 >> filename2
— filename1 content is appended to the end of filename2.
Creating file:
cat > filename
— Enter the text, once all the text is entered press cntrl + d, which saves the file content.
Appending to existing File:
cat >> filename
— Enter the text, it will append the content to the end of the filename , once all the text is entered press cntrl + d, which saves the file content.
3. passwd
passwd command is used to change the password associated with our individual account name.
When you type this command it will ask you for the old password and the new password.
4. pwd
pwd (present working directory) tells you your current directory.
5. cd
cd is used to change directories.
cd new-directory
Change the current directory to new-directory
“cd ~” or simply “cd”
Change the current directory to users home directory.
cd ~username
Change the current directory to username’s home directory.
cd –
For changing directory to previous working directory
cd .
Change working directory to parent directory.
cd <pattern1> <pattern2>
To change the current directory to other directory with only small difference in one of the intermediate directory name
Ex: If the current directory is “/user/path01/dir”
to change the directory to “/user/path02/dir” use this command
cd 01 02
6. mkdir
mkdir (make directory) is used to create a new directory,
It can take more than one parameter, interpreting each parameter as another directory to create.
mkdirDirname
To create the directory Dirname
mkdir -m <Permission> Dirname
To create the directory Dirname with the given permission
Ex: mkdir -m 777 Dirname
7. rmdir
rmdir (remove directory) is used to remove a directory,
rmdirDirname
Deletes the empty directory Dirname can be used only when the directory is empty.
If the directory is not empty the below command can be used to delete the directory recursively
rm –r dirname
8. cp
cp is used to copy contents of file1 to file2
cp file1 file2
contents of file1 is copied to file2 in the same directory
cp folder1/file1 folder2
contents of file1 is copied to file1 in the inside of folder2 directory
cp –r dir1 dir2
To copy directory from one location to another.
9. rm
rm is used to remove a file.
rm filename
removes a file named filename
rm –f filename
-f option is used to remove the file forcefully.
rm –r dirname
to remove the nonempty directory “dir”
10. mv
mv is used to move a file.
mv filename1 filename2
mv command moves the file from filename1 to filename2.
If the filename1 and filename2 are pointing to the same directory then it renames the file filename1 to filename2.
11. chmod
Chmod (change mode) is used to change the permissions on a file.
There are two ways to do it.
chmod [number][number][number] filename
Number = (read)4 + (write)2 + (execute)1
Example: chmod 754 filename
for owner: read, write and execute permissions (4+2+1)
for group: read and execute permissions (4+0+1)
for others: only read permission (4+0+0)
chmod [u/g/o/a][+/-/=] filename
u=owner, g=group, o=others, a=all
“+”=Add permission, “-”=remove permission, “=“=assign permission
Example1: chmod a+r filename
above command adds the read permission to all the users.
Exmple2: chmod o-w filename
above command removes the write permission from other users.
12. du
du (disk usage) will count the amount of disk space for a given directory, and all its subdirectories take up on the disk.
Example:
du –h dirname
Above command gives disk space for dirname, and all its subdirectories in the human readable format.
13. df
df (disk filling) summarizes the amount of disk space in use. For each file system, it shows the total amount of disk space, the amount used, the amount available, and the total capacity of the file system that’s used.
Example :
df –kh dirname
Above command gives total amount of disk space, the amount used, the amount available, and the total capacity of the file system that’s used for dirname.
14. more
more is a command to view (but not modify) the contents of a text file one screen at a time.
Example 1:
more filename
Use space button to scroll down, and press “q” to stop viewing the contents.
Example 2:
more -2 filename
This command can be used to view two lines at a time(you can change this to other numbers too).
15. less
less is a command similar to more, but which allows backward movement in the file as well as forward movement.
Example 1:
less filename
Use the arrow buttons to scroll.
16. head
head will display the first lines in the listed files, by default it displays first 10 lines of the file .
Common Unix Commands Pdf
example1:
head filename
This command displays first 10 lines of the filename
example1:
head -25 filename
This command displays first 25 lines of the filename.
17. tail
tail will display the last lines in the listed files, by default it displays last 10 lines of the file .
example1:
tail filename
This command displays last 10 lines of the filename.
example1:
tail -25 filename Tattoo studio management software for mac.
This command displays last 25 lines of the filename.
18. grep
grep is the generalized regular expression parser.
This command is used to search for the pattern in the file.
Example 1:
grep “pattern“ filename
This command displays all the lines in the filename which contains the pattern “pattern” (case sensitive).
Example 2:
grep -i “pattern“ filename
This command displays all the lines in the filename which contains the pattern “pattern” (case insensitive).
Example 3:
grep –c “pattern“ filename
This command displays the count of the lines having the pattern “pattern”
Example: 4
grep -v “pattern“ filename
This command displays the lines of the file which does not have the pattern “pattern”.
Example 5:
grep -l “pattern“ *
This command displays the filenames in the current directory which has the pattern “pattern“.
19. wc
wc (word count) simply counts the number of words, lines, and characters in the file(s).
wc [-option] filename
The three parameters, clw, stand for character, line, and word respectively, and tell wc which of the three to count.
Example :
wc –l filename
This command will display the number of the lines in filename.
20. cmp
cmp compares two files. The first must be listed on command line, while the second is either listed as the second parameter or is read in form standard input.
cmp is very simple, and merely tells you where the two files first differ.
Example :
filename1 filename2
21. diff
diff utility is a data comparison tool that calculates and displays the differences between two files.
Example:
diff file1 file2
The first line of the diff output will contain:
1.line numbers corresponding to the first file,
2.a letter (a for add, c for change, or d for delete), and
3.line numbers corresponding to the second file.
Example:
“2a3” means: “After line 2 in the first file, a line needs to be added: line 3 from the second file.”
“4d3” means: “You need to delete line 4 in the first file so that both files sync up at line 3.”
“2,4c2,4” means: “Lines 2 through 4 in the first file need to be changed in order to match lines 2 through 4 in the second file.
22. gzip/gunzip/zcat
gzip:
gzip compresses files, it deletes the files specified on the command line and replaces them with files that have an identical name except that they have “.gz” appended to them.
Example:
gzip filename
gunzip:
gunzip uncompresses a file that was compressed with “gzip” or “compress”.
Example:
gunzip filename.gz
zcat (to view the data in compressed file):
zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output.
Example:
zcat filename.gz
23. tr
The “translate characters” command operates on standard input-it doesn’t accept a filename as a parameter.
It replaces all occurences of first parameter with the second parameter.
Example 1:
tr “r” “p”
This command replaces the character “r” with “p.
Example 2:
tr “[:lower:]” “[:upper:]“
This command converts lower case letters to upper case.
Example 3:
tr -d “pattern“
This command delete characters in pattern from the input.
24. scp
scp stands for “secure copy”, and is used to copy the files between two different servers.
Syntax:
scp filename user_id@rem_servername:remote_dir_path
Example:
scp file1 trenovision@rserver:/home/user/trenovision
This command copies the file “file1” from the current server to the “rserver” server and to the path “/home/user/trenovision”.
25. date
Different usage with Output:
To get current data with Timestamp and time in Unix/Linux/Bash/Shell scripts.
date
Sun Mar 29 02:10:38 EDT 2015
date +%Y%m%d%H%M%S
20150329021052
date “+%Y-%m-%d %H:%M:%S.%N”
2015-03-29 02:11:12.784721000
Bash Date Formats:
- Y= Year in YYYY format
- m=Month in MM format
- y=Year in YY format
- d=day in DD format
- H=Hour in HH format
- M=Minute in MM format
- S=Seconds in SS format
- N=Nano seconds in NNNNNNNN format
Subtracting dates with output:
date -d”1 day ago“ — for taking yesterdays date and time.
Sat Mar 28 02:15:32 EDT 2015
(current date is “Sun Mar 29 02:15:32 EDT 2015 “)
date -d”1 hour ago“ — for taking 1hour ago time
Sun Mar 29 01:17:40 EDT 2015
26. sed
sed command is used to replace the text in a file.
Example 1:
sed ‘s/oldvalue/newvalue/g’ filename
Above command will replace all occurrence of the oldvalue with newvalue in the file filename(file content is modified) and will display it on standard output.
Example 2:
sed –I ‘s/oldvalue/newvalue/g’ filename
Above command will replace all occurrence of the oldvalue with newvalue in the file filename(file content is modified).
Example 3:
sed ‘/^$/d’ filename
This command will delete the empty lines in the file(file content is not changed) and displays the result on the standard output.
27. awk
awk is one of the most powerful tools in Unix used for processing the rows and columns in a file. Awk has built in string functions and associative arrays. Awk supports most of the operators, conditional blocks, and loops available in C language
Example1 :
awk -F “_” ‘{print $1}‘ filename
This command displays the first column data in the file filename(“_” is the column delimiter).
Example 2 :
awk ‘{ if($2 “pattern”) print $0;}’ filename
This awk command checks for the string “pattern” in the 2nd column and if it finds a match then it will print the entire line.
28. Uninstall logitech camera drivers for mac. touch
touch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. If the file does not exist then it creates a zero byte file.
Example1 :
touch filename
This command will update the timestamp of the file filename.
Example 2:
touch -t 1502250512 filename
Above command updates the timestamp of the file filename to year 15, month 02, day 25, hour 05 and minute 12.
29. Connecting to db2
Below example will explain you how to connect to db2 through Unix script.
db2 connect to database user username using password
db2 -xr filepath “sql query”
db2 terminate
After running the above command you will get the “sql query“ results in the file “filepath“.
29. Connecting to Teradata
Below example will explain you how to connect to Teradata through Unix script.
bteq<<EOF
.SET ERROROUT STDOUT;
List Of All Unix Commands With Examples Pdf Example
.logon databasename/username,password
.export report file=filepath
Select query;
.export reset
.logoff
.quit
EOF
Above command will connect to Teradata database and will run the sql query “Select query” and will store the result in the file “filepath”.
30. tar
The command “tar” stands for tape archive. The tar command used to rip a collection of files and directories into highly compressed archive file.
Example 1:
tar -cvf TarName.tar DIRNAME
This command will create the tar file for the directory DIRNAME.
Example 2:
tar -xvf TarName.tar
This command will untar the tar file TarName.tar
and get the directory DIRNAME content to the current directory.
31. finger
finger is a command to find information about computer users. It usually lists the login name, the full name, and possibly other details about the user you are fingering.
Example 1:
finger username
Displays the information about the user username
Example 2:
finger -s trenovision
Displays the information of the all the users who has the name trenovision.
32. mailx
mailx command is used to send the mail to a given set of users.
Example 1:
cat filename mailx –s “Subject” abcd@abc.com
This command will send the mail to abcd@abc.com with the subject “Subject” and the mail body as the conectn of the file “filename”
Example 2:
(cat mailbody.txt; uuencode attachmnt.txt attachmnt.txt ) mailx -s “Subject” attachmnt.txt
This command can be used to send the mail with mail body subject and the attachment.
33. ftppwd
ftppwd command can be used to set and view the password for the given username and database combination in the environment, setting password does not mean that it will change the users password, it means that it will set it in the environment and it can be re fetched using the same command. Only the user who set this password in his environment can see the password.
Note:
If the user changes the password for the username in the given database, it is necessary that he needs to set the password again using ftppwd command, otherwise it will reflect the old password only.
Example 1:
ftppwd -s <PASSWORD> <DATABASE_NAME> <USER_NAME>
This command will set the password PASSWORD for the user name USER_NAME for the database DATABASE_NAME in the environment.
Example 2:
ftppwd <DATABASE_NAME> <USER_NAME>
This command is used to fetch the password for the username USER_NAME in the database DATABASE_NAME which was set using ftppwd –s option.
34. find
The find command is used to search any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories too.
Example 1:
find
This command lists out all the files in the current directory as well as the subdirectories in the current directory.
Example 2:
find directory_path -name “filename”
This command searches for file filename in the directory_path and its sub directory. Use –iname if you want to make search as case insensitive.
Example 3:
find -name ‘*.doc’ -o -name ‘*.txt’
This command can be used to search two different kind of files.
Example 4:
find ./test -type d -name “abc*”
This command can be used to find only the directoies.
Example 5:
find . -mtime 10
This command can be used to find all the files which are modified 10 days back.
35. alias
List Of All Unix Commands With Examples Pdf File
The alias command allows you to make new shortcuts and synonyms for commonly used commands.
Example 1:
alias lt=”ls -lrt tail”
After running this command, if you type just “lt” it gives you the result of “ls –lrt tail”.
Basic Unix Commands With Examples
Example 2:
alias day_ago=”date -d’1 day ago’
After running the above command if you type “day_ago” it returns the yesterdays date.