![]()
Comandos Básicos do UNIX
Here are some basic commands of the UNIX system and some hints on how to use these commands.
José Augusto P. BRITO http://www.mackenzie.br/brito![]()
UNIX - Principais Comandos ls
cd
mkdir
rmdir
cp
mv
rm
man
more
pwd
echo
finger
grep
kill
passwd
ps
whois
List the contents of a folder: "ls"
Use this command to list the contents of the current folder. This will display all files and folders within the current folder in a columnar format.
You may change the format in which ls displays your folder listing by adding options to the ls command. To add an option to the command, follow the ls command with a minus sign '-' and the option(s) you wish to add. For example, ls -l will list the current folder in long format, showing size, date, and permissions.
The command syntax for ls is : ls [ -aAcCdfFgilLqrstux ] filename
The "change directory" command is used to switch from one folder to another. The purpose of having multiple folders is to enable you to easily organize your files. Your directory structure should resemble an filing cabinet, with folders (directories) for each set of files.
Using cd without a directory name following it will return you to your home directory. To change to a directory called "skiing", you would type:
- cd skiing.
The command syntax for cd is :
- cd [directoryname]
The"make directory" command is used to create a new folder. As noted above, a folder serves to organize files in a manner to similar to a filing cabinet. However, unlike most filing cabinets, a single folder may contain several sub folders. To create a folder called "banff", you would type:
- mkdir Banff
The command syntax for mkdir is:
- mkdir directoryname
The "remove directory" command is used to permanently delete your folders. The folder you wish to remove must be empty before using the rmdir command. To remove a folder called "bigsky", you would type:
- rmdir bigsky
The command syntax for rmdir is:
- rmdir directoryname
The "copy" command is used to copy files from one folder to another, leaving the original in place. To copy a file named "tahoe.ps" from your home directory to a folder named "goodskiing", you would type:
- cp tahoe.ps goodskiing
If you wished to rename the copied files, you would type:
- cp tahoe.ps goodgkiing/newname.ps
The command syntax for cp is:
- cp [ -ip ] filename1 filename2
The "move" command is used to move or rename files.
To move a file named "panorama.ps" from your home directory to a folder named "goodskiing", you would type:
- mv panorama.ps goodskiing
The "move" command can also be used to rename files or folders. If you wanted to rename a file called "mammoth.ps" to "BIG.ps" (remember that UNIX is case sensitive!), you would type:
- mv mammoth.ps BIG.ps
The command syntax for mv is:
- mv [ -fi ] filename1 filename2
The "remove" command is used to permanently delete your files from your folders. To remove a file named "whistler.ps", you would type:
rm whistler.ps
To remove multiple files, use the remove command followed by the names of the files, separated by spaces. For example
- rm file1 file2 file3
The command syntax for rm is:
- rm [-fir] filename
The man command will display the manual pages for most UNIX commands. For example, if you require help on the move command which appears above, you would type:
- man mv.
The command syntax for man is:
- man commandname
more
The command more my_file displays the text of my_file one page at a time. To see the next page, hit the space bar; to see the previous page, type b; to quit paging the file, type q.
pwd
The command pwd prints the pathname of the current, or working, directory.
echo
The command echo MY_VARIABLE displays the current value of environment variables. Two variables that might interest you at some point are $PRINTER and $DISPLAY.
finger
The command finger user_name gives you information on the user specified by user_name.
grep
The command grep string filename searches filename for string. It outputs every line which contains string. The form grep -v string filename outputs every line which does not contain string.
kill
The command kill my_process sends a terminate signal to the process specified by the process id (PID) my_process. In cases where the terminate signal does not work, the command kill -9 my_process sends a kill signal to the process. For info on getting the PID for a process, see ps.
passwd
The command passwd allows you to change the password you use to login to the computer. The process is self-explanatory once you type the command.
ps
The command ps lists the processes running on your machine. The form ps gux lists only your processes. The form ps aux lists all processes running on your machine. The second column of the listing, the PID column, provides the information required by the kill command.
whois
The command whois lookup_string performs a directory lookup on persons at your home institution, where lookup_string is all or part of someone's first name, last name, or phone number.
To find a directory named ' docs ' on the system, searching from the root directory, display in the results on the screen
find / -type d -name docs -print
Copyright - J.A.P. Brito - 08/1999