UNIX COMMANDS
UNIX commands:
- To create a directory.
- Syntax : mkdir <directory name>
- Example : mkdir oslab
- To rename a directory.
- Syntax : mv <directory 1> <directory 2>
- Example : mv CIVIL IT
- To change the directory.
- Syntax : cd <directory name>
- Example : cd IT1
- To copy the directory and its file to another directory.
- Syntax : cp –r <source directory> <destination directory>
- Example : cp –r IT1/ IT2
- To remove an empty directory.
- Syntax : rmdir <empty directory name>
- Example : rmdir IT1
- To remove an non–empty directory.
- Syntax : rmdir –r <directory name>
- Example : rmdir –r IT2
- To print present working directory. / To display complete path of the working directory.
- Syntax : pwd
- To create a file.
- Syntax : vi <file name>
- Example : vi aa.txt
- To rename a file.
- Syntax : mv <old file name> <new file name>
- Example : mv aa.txt a1.txt
- To view a file.
- Syntax : cat <file name>
- Example : cat a1.txt
- To copy files.
- Syntax : cp <source filename> <destination filename>
- Example : cp a1.txt a2.txt
- To move files.
- Syntax : mv <filename 1> <filename 2>
- Example : mv a1.txt a2.txt
- To concatenate two files.
- Syntax : cat <file 1> <file 2> > <new file 3>
- Example : cat a1.txt a2.txt > a3.txt
- To display the file contents.
- Syntax : cat <file name>
- Example : cat a3.txt
- To display the file contents with line number.
- Syntax : cat –n <file name>
- Example : cat –n a3.txt
- To create a file using cat command
- Syntax : cat > <filename>
<Type the information and press <ctrl+d> to terminate>
- Example : cat > a4.txt
- To append the contents of one file to another.
- Syntax : cat <file 1> >> <file 2>
- Example : cat a1.txt >> a2.txt
- To append more than one file.
- Syntax : cat <file 1> <file 2> <file 3>…>> <destination file>
- Example : cat a1.txt a2.txt a3.txt >> aa.txt
- To link files. <Creates a link between two files. changes in file will reflect in the other file also>
- Syntax : ln <file 1> <file 2>
- Example : ln a1.txt a2.txt
- To link 5 files.
- Syntax : ln <source directory> <destination directory>
- Example : ln /home/anu/IT/* /home/anu/IT/
- To sort files in alphabetical order / Display the file contents in descending / ascending order.
- Syntax : sort <file> // ascending order
- Example : sort a1.txt
- Syntax : sort –r <file> // descending order
- Example : sort –r a1.txt
- To list the contents of a directory.
- Syntax : ls
- To list all directories of a user.
- Syntax : ls –l | egrep ‘^d’
- To list only files from a directory.
- Syntax : ls –l | egrep –v ‘^d’
- To list hidden directories.
- Syntax : ls -a
- To display all files, subdirectories and files in the subdirectories including their sizes.
- Syntax : ls -lR
- To list only the subdirectories available in the present working directory.
- Syntax : ls –lR | egrep –v ‘^d’
- To list all directories / files that start with a specific character.
- Syntax : ls <character>*
- Example : la a*
- To list all files in current directory whose 2ndcharacter is a digit.
- Syntax : ls ?[0–9]*
- To list files and directories recursively on a single line.
- Syntax : ls –LR
- To list all files which has dot at the end
- Syntax : ls *.
- To list all filenames which has a specific extension
- Syntax : ls *.<extension>
- Example : ls *.txt
- To list the file attributes and file size.
- Syntax : ls -l
- To change the file to read only mode. / to change the permission of a file
- Syntax : chmod u-wx <file>
chmod g-wx <file>
chmod o-wx <file>
- Example : chmod u-wx a1.txt
chmod g-wx a1.txt
chmod o-wx a1.txt
- To view one page of a file.
- Syntax : ls –l | more
- To view the files page by page.
- Syntax : ls –l | more
<press space bar to view next page>
- To view first 10 lines of a file / to display the beginning of a file
- Syntax : head <file>
- Example : head a1.txt
- To view last 10 lines of a file / to display the end of a file
- Syntax : tail <file>
- Example : tail a1.txt
- To display only the first two characters of all lines from a file.
- Syntax : cut –c1–2 <file name>
- Example : cut –c1–2 aa.txt
- To combine two files.
- Syntax : cat <file 1> <file 2> > <new file 3>
- Example : cat a1.txt a2.txt > a3.txt
- To combine two files without duplicates.
- Syntax : cat <file 1> <file 2> | sort –u > <new file 3>
- Example : cat a1.txt a2.txt | sort –u > a3.txt
- To add “;” to the end of the file.
- Syntax : <cat <file>; echo “;”> > <new file>
- Example : <cat a1.txt; echo “;”> > a5.txt
- To delete the 7th line of a file.
- Syntax : sed ‘<line number>d’ <file>
- Example : sed ‘7d’ a1.txt
- To split a file into smaller number of files with 3 lines in each file.
- Syntax : split –l <number of lines> <file>
- Example : split –l 3 aa.txt
- To convert lowercase to uppercase.
- Syntax : cat <file> | awk ‘{print toupper<$0>}’
- Example : cat aa.txt | awk ‘{print toupper<$0>}’
- To convert uppercase to lowercase.
- Syntax : cat <file> | awk ‘{print toupper<$0>}’
- Example : cat aa.txt | awk ‘{print tolower<$0>}’
- To combine two strings.
- Syntax : echo <string1><string2>
- Example : echo “IRTT” “CIVIL”
- To count the number of words in a file.
- Syntax : wc –w <file>
- Example : wc –w aa.txt
- To count the number of lines in a file.
- Syntax : wc –l <file>
- Example : wc –l aa.txt
- To count the number of characters in a file.
- Syntax : wc –m <file>
- Example : wc –m aa.txt
- To search for a specific word in a file.
- Syntax : grep <word> <file>
- Example : grep civil aa.txt
- To count the number of occurrence of a character in a file.
- Syntax : grep –c <word> <file>
- Example : grep –c civil aa.txt
- To search for a specific file in a directory.
- Syntax : find <present working directory> –type f –name <file>
- Example : find /home/anu –type f –name aa.txt
- To translate the character “I” in a file to “E”.
- Syntax : cat <file> | tr <original character> <replace character>
- Example : cat aa.txt | tr I E
- To change the password.
- Syntax : passwd
- To view the commands which was executed
- Syntax : history
- Show manual for a command
- Syntax : man <command>
- Example : man cat
- To clear the screen.
- Syntax : clear
- To print todays date and calendar of the current month using a single command.
- Syntax : cal
- To print the calendar for year 2013
- Syntax : cal <year>
- Example : cal 2013
- To print the calendar for 2012 for the month of March.
- Syntax : cal <month> <year>
- Example : cal 3 2012
- To print date and time.
- Syntax : date
- Display user name.
- Syntax : whoami
- To find out who is logged in. / To print who is using the system presently.
- Syntax : who
- Display users full detail, user-id and group-id.
- Syntax : id
Converted to HTML with WordToHTML.net | Document Converter for Windows
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu