Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unix Commands

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Basic UNIX Commands

1. WHO It displayes the all users in the system 2.WHO AM I It displayes the information about the current user format: username terminal number example: naresh tty3a

date and time jun 10 09:15

3.TOUCH It creates the new file with empty space . We can create more number of files at a time. example: touch file1 file2 file3 4.CAT It creates the new file with entered data.after entering the data press CTRL+D to end the file. example: cat > file1 we can use CAT command to display the file contents example: cat file1 5.cat file1 file2 > newfile this command creates "newfile" and insert the two files data one after other (file1 and file2) If the "newfile" already exists then it overwritten with new files data 6.cat file1 file2 >> newfile If the "newfile" already having some data then we use this command to append the data to the precious data. 7.cp letter.a letter.b letters This command copies letter.a and letter.b to the directory letters 8.cp /usr/aa16/chapter1 /usr/aa16/newbook/chap1 This command copies the chapter1 file to newbook directory 9.rm -i file It removes the "file" with interactively, It asks for confirmation before deleting the file. 10.mv test sample This command renames the file test to sample We can use this command to rename the directories also 11.ls By using this command we can display the files 12 ls -a By using this command we can display the files even hidden files also displayed TO CREATE HIDDEN FILES : Create the file starting with "."

example : cat > .filename 13. ls p* It displayes the files whose name starts with "p" example : pain parse pocket 14. ls ?aim It displayes the files whose name starts with any letter and followed by "aim" example : pain main rain 15. ls /mydir/*x It display the files in the directory "mydir" if the last letter is "x" 16. ls [aeiou]* It display the files whose name starts with a,e,i,o,u 17 ls [!aeiou]* It display the files whose name starts with other than a,e,i,o,u 18. ls [a-m][b-d]?? It display the files whose name is starts with "a to m" and the second character is in the range of " b to d" and third and fourth are valid characters. example : bcff eckp 19. ls -l It displays the files with complete details 20. ln filename filename2 This command creates another link for the file "filename" 21. chmod By using this command we can chane the permissions We have three permissions read write execute Notation ally these are denoted with r is for read w is for write x is for execute Numerically these are denoted with 4 is for read 2 is for write

1 is for execute example Chmod 700 file1 It gives the permissions as Rwx for user None for group None for others Another form of chmod command is Chmod [who] [+/-/=] [permissions] filename Here Who means user or group or other Owner is denoted with u Group is denoted with g Others is denoted with o If none is specified all are assumed. + is to add - is to remove = is to truncate and assigns the new permissions Example Chmod +w file1 It gives the write permissions to all Chmod go-x file1 It removes the executable permissions form group and other. Chmod go+r,go-w file1 It gives the read permissions to group and others, and removes the write permissions from group and others Chmod 744 file1 It gives the permissions like rwxrr-- to file1 22. umask When u create any file some permissions are automatically assigned How these permissions are assigned? The default system wide permissions for unix are : 666 Subtract these permissions frome umask permissions then we will get the required permissions. Example Umask By using this command we can retrive the umask(user file creation mask) permissions For example these are 0022

First 0 indicates that what follows is an octal number Second 0 indicates there is no permissions denied from owner First 2 indicates that denied the write permissions from group Second 2 indicates that denied the write permissions from others For file the default permissions are 666-022=644(rw for users, write for group, write for others) For directory the default permissions are 777-022=755(rwx for users, rx for group, rx for others) To change the umask value : Command: Umask value Example Command: Umask 242 Default permissions are : For file the default permissions are 666-242=424(read for users, write for group, read for others) For directory the default permissions are 777-242=535(rx for users, wx for group, rx for others) 23. rm Command : rm f letter This command removes the file letter forcely . that is even if the file is write protected 24. ls r : Command : ls r this command displayes all the files in the current directory ,including the files present in the subdirectories 25. ls s : Command : ls s This command displays the files with size ( in blocks) 26. ls i : Command : ls i This command displays the files with inode number 27. lc : Command : lc This command displays the files in column wise 28. lf :

Command : lf This command displays the files Ends with * for executable files Ends with / for sub-directories 29. pwd : Command : pwd This command displayes the present working directory. 30. mkdir : Command : mkdir dirname It creates the directory dirname Command : mkdir p pathname It creates the complete path as one by one directory Example : Command : mkdir p home/datastage/naresh This command first creates the directory home then it creates datastage then it creates naresh. 31. rmdir : Command : rmdir dirname It removes the directory dirname Command : rmdir p path It removes all the directories from right to left 32. cd Command : cd dirname This command would take you in dirname Command : cd This command would take you in to the home directory 33. bc : command : bc this command is for calculator purpose 34. factor : Command : factor It returns the prime factors of the given number 35. logname : Command : logname This command prints the login name of the user

36. id : Command : id This command prints the userid(uid) and groupid(gid) of the current user. 37. uname : Command : uname It displayes the name of the unix system Command : uname x It displayes the information like Release number Version number OEM number Type of the microprocessor Typr of the bus the microprocessor has Number of CPUs present in the host machine

38. tty : Command : tty it displayes the terminal file name 39. date : Command : date It displayes the current date and time 40. df : Command : df It prints the disk free information in blocks Command : df ivt It prints the disk free information in detail format in blocks 41. dfspace : Command : /etc/dfspace It displayes the free disk space in megabytes(MB) 42. du Command : du It displayes the disk usage of the current directory Command : du /dev It displaces the disk usage of sub directories in the /dev directory Command : du s /dev It displays the disk space in the /dev directory

43. ulimit(user limit) : Command : ulimit It displayes the limit of the file size to be created. 44. passwd : Command : passwd By using this command we can change the password In unix every pass word is stored in the directory /etc/passwd Example : $cat /etc/passwd Output : Aa6:x:207:50:user number 6:/usr/aa6:/bin/sh Here Aa6 login name X is for encrypted password 207 is userid 50 is groupid User number is comment /usr/aa6 default working directory /bin/sh is for default working shell 45 . cal Command : cal It displayes the callender Command : cal 2 1997 It displayes the calendar for February 1997 46. banner : Command : banner string It displays the string as a banner. 47. ps(process id ) Command : ps It prints the process ids for the current user running on the terminal Command : ps a It prints the process ids for all the users Command : ps u userloginname It prints the process ids for the particular user userloginname Command : ps t terminalname It prints the process ids for the particular terminal terminalname Command : ps f It prints the process ids for the current user in full listing.

Command : ps e It prints the process idd for every process running at that instant Here e stands for every process 48. background process : Command : command filename > outputfilename& If u want to run a process in the background we place a & symbol in the end of the command. Example Command : sort employee > emp.out& Output : 17354(this is the process id) In this example sorts the employee data and output is stored in the file emp.out .this process is runs in the back ground . When we use this command it prints the PID . By using this pid we can check where that process is completed or not. 49. nohup : By using this command we can execute the process with out die even you are logout Example : Command : nohup sort employee > outputfile 50. kill : Command : kill pid This command kills the process Example Command : kill 17567 This command kills the process 17567 Command : kill -9 2234 This command kills the process 2234 forcely. 51 . nice (changing process priority) : By using nice command we can change the priority of the process execution The default value for nice command is 20. We can change the nice values in the ration of 0-19, Lowest nice values having highest priority and greater nice value having low priority Example : Nice value=20 is high priority than Nice value =25 To increase the nice value : Command : nice -10 sort filename > outputfilename Nice value = 20+10 =30 To decrease the nice value: Command : nice 10 sort filename > outputfilename Nice value = 20-10 =10 To view the nice values: Command : ps l Scheduling :

52 . at By using this command we can schedule the particular file or particular commands to be execute. Command : at 5:00pm Clear > /dev/tty3c Echo hai this is naresh > /dev/tty3c Ctrl + d Output : Job 3456765.a at Fri jun 5:00 IST 1996 When we execute this command , it schedules the above two commands (clear and echo) these command will execute in the mentioned time If you didt give the output as /dev/tty3c is send to the mail Command : at r jobid This commands removes the specified job from the scheduler Example : at r 3456765.a Command : at l This commands prints the scheduled jobs Examples : Commands : $at 09:15 am Mar 24 $at 9:15 am Mar 24 $at now +10 minutes $at now + 1 day $at 7 pm Thursday next week Schedule the file by using at command : First create a file with required commands Command : cat >filename Clear Echo hai this is naresh Ctrl d Now we can schedule this file using at command Command : at 5:00 < filename Output : job 39247346.a at Fri Jun 14 5:00 IST 1996 Note : To use at command our user name must consist in the directory /user/lib/cron/at.allow We cannot use the at command if our user name consist in the directory /user/lib/cron/a,deny

53 . batch : By using this command we can schedule the jobs with out providing the time UNIX automatically decide when the have to execute Command : $batch Clear Echo hai this is naresh Ctrl d Output : Job 2324234.b at Fri Jun 14 5:00pm IST 1996 54. crontab : By using this command we can schedule the files with great features First create a file : Cat > filename 30 10 1 * * echo work hard for this month 0 10 13 8 * mail aa23 < birthday.file Ctrl d Command : crontab filename This file filename was executes in the given time Command : crontab l To display the list of crontab files Command : crontab r To remove the crontab entries from scheduler.

You might also like