Following is a very brief introduction to some useful Unix commands, including examples of how to use each command. For more extensive information about any of these commands, use the Show On this page:
calThis command will print a calendar for a specified month and/or year. To show this month's calendar, enter: cal To show a twelve-month calendar for 2008, enter: cal 2008 To show a calendar for just the month of June 1970, enter: cal 6 1970 catThis command outputs the contents of a text file. You can use it to read brief files or to concatenate files together. To append cat file1 >> file2 To view the contents of a file named cat myfile Because For more, see Combine several text files into a single file in Unix. cdThis command changes your current directory location. By default, your Unix login session begins in your home directory. To switch to a subdirectory (of the current directory) named cd myfiles To switch to a directory named cd /home/dvader/empire_docs To move to the parent directory of the current directory, enter: cd .. To move to the root directory, enter: cd / To return to your home directory, enter: cd chmodThis command changes the permission information associated with a file. Every file (including directories, which Unix treats as files) on a Unix system is stored with records indicating who has permission to read, write, or execute the file, abbreviated as r, w, and x. These permissions are broken down for three categories of user: first, the owner of the file; second, a group with which both the user and the file may be associated; and third, all other users. These categories are abbreviated as u for owner (or user), g for group, and o for other. To allow yourself to execute a file that you own named chmod u+x myfile To allow anyone who has access to the directory in which chmod o+rx myfile You can view the permission settings of a file using the Note: Be careful with the For more, see Manage file permissions on Unix-like systems. cpThis command copies a file, preserving the original and creating an identical copy. If you already have a file with the new name, cp -i oldfile newfile To copy a file named cp -i /home/dvader/notes/meeting1 . The To copy a file named cp -i oldfile ~/mystuff/newfile The Note: You must have permission to read a file in order to copy it. dateThe To see this information, enter: date dfThis command reports file system disk usage (that is, the amount of space taken up on mounted file systems). For each mounted file system, To find out how much disk space is used on each file system, enter the following command: df If the df -k duThis command reports disk usage (that is, the amount of space taken up by a
group of files). The To find out how much disk space your files take up, switch to your home directory with the du The numbers reported are the sizes of the files; on different systems,
these sizes will be in units of either 512 byte blocks or kilobytes. To learn which is the case, use the findThe To find all of the files named find . -name myfile.txt -print To look in your current directory and its subdirectories for all of the files that end in the extension find . -name "*.txt" -print In these examples, the find /home/user/myusername/ -name myfile.txt -print On some systems, omitting the final As a shortcut for searching in your home directory, enter: find "$HOME/" -name myfile.txt -print For more, see Use the Unix find command to search for files. ifconfigThis command is used to configure network interfaces (wifi, ethernet, etc.). Generally, it is used during initial network configuration and during network troubleshooting. To view all active network interfaces on a given machine, enter: ifconfig To view all network interfaces, active and inactive, on a given machine, enter: ifconfig -a jobsThis command reports any programs that you suspended and still have running or waiting in the background (if you had pressed jobs Each job will be listed with a number; to resume a job, enter %2 This command is only available in the killUse this command as a last resort to destroy any jobs or programs that you suspended and are unable to restart. Use the jobs command to see a list of suspended jobs. To kill suspended job number three, for example, enter: kill %3 Now check the kill -9 %3 less and moreBoth To read the contents of a file named less textfile The ls -la | less In both examples, you could substitute Note: Do not use lpr and lpThese commands print a file on a printer connected to the computer network. The To print a file named lpr -Plp1 myfile To print the same file to the same printer with lp -dlp1 myfile Note: Do not print to a printer whose name or location is unfamiliar to you. lsThis command will list the files stored in a directory. To see a brief, multi-column list of the files in the current directory, enter: ls To also see "dot" files (configuration files that begin with a period, such as ls -a To see the file permissions, owners, and sizes of all files, enter: ls -la If the listing is long and scrolls off your screen before you can read it, combine ls -la | less For more, see List the files in a directory in Unix. manThis command displays the manual page for a particular command. If you are unsure how to use a command or want to find out all its options, you might want to try using For example, to learn more about the man ls To learn more about man man If you
are not sure of the exact command name, you can use man -k keyword Replace mkdirThis command will make a new subdirectory. To create a subdirectory named mkdir mystuff To create a subdirectory named mkdir /tmp/morestuff Note: To make a subdirectory in a particular directory, you must have permission to write to that directory. mvThis command will move a file. You can use Note: As with the To rename a file named mv -i oldname newname To move a file named mv -i newhw/hw1 oldhw If, in this last operation, you also wanted to give the file a new name, such as mv -i newhw/hw1 oldhw/firsthw ps The ps -alxww To display similar information in System V, use the arguments: ps -elf For more about pwdThis command reports the current directory path. Enter the command by itself: pwd For more, see Determine your current working directory in Unix. rm This command will remove (destroy) a file. You should enter this command with the rm -i junk Note: Using To remove a non-empty subdirectory, rm -rf oldstuff
Note: Using this command will cause ls -R oldstuff | less rmdir This command will remove a
subdirectory. To remove a subdirectory named rmdir oldstuff Note: The directory you specify for removal must be empty. To clean it out, switch to the directory and use the setThis command displays or changes various settings and options associated with your Unix session. To see the status of all settings, enter the command without options: set If the output
scrolls off your screen, combine set | less The syntax used for changing settings is different for the various kinds of Unix shells; see the vi This command starts the vi text editor. To edit a file named
vi myfile The vi editor works fairly differently from other text editors. If you have not used it before, you should probably look at a tutorial, such as Use the vi text editor. The very least you need to know to start using vi is that in order to enter text, you need to switch the program from command mode to insert mode by pressing w and who The Related documentsWhich command is used to remove empty lines from a file?Using awk. Using the awk command, we can remove blank lines in different ways.
How will you remove blank lines from a file using grep?By Using [: space:]
grep's –v option will help print lines that lack blank lines and extra spacing that is also included in a paragraph form. You will see that extra lines are removed and output is in sequenced form line-wise. That's how grep –v methodology is so helpful in obtaining the required goal.
Which is the command used to remove or delete a file without a confirmation message?Syntax: rm command to remove a file
When rm command used just with the file names, rm deletes all given files without confirmation by the user.
Which command used for deleting line?To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete.
|