Learn about the Unix commands with their usages and examples.
This Unix command tutorial introduces you with some of the most popular and useful commands used in nix operating system to get you started with Unix.
All Unix OS comes with online manual system, man, which can be used used as ,man
, to get more details and complete set of options.
Coverted in this Unix Command Tutorial
- [Wild Cards](#Wild Cards )
- [Directory operations](#Directory Operations)
- [File edit/create/view](#File edit/create/view)
- [File operation](#File Operation)
- [Find files , directories](#Find Files , Directories)
- [Process Operations](#Process Operations)
- [User administration](#User Administration)
- [System Status](#System Status)
- [Environment Variable](#Environment Variable)
- Connectivity
- [Backup and Restore](#Backup and Restore)
| Wild Cards |
|---|
| * |
| ls *.c |
| ? |
| ls prog? |
| Directory Operations |
|---|
| Change |
| Make |
| Move |
| Remove |
| File edit/create/view |
|---|
| vi - vi full screen editor |
| ed - Line Text editor |
| count - Line, word, & char |
| Text content display - List contents of file at once |
| Text content display by screen : List contents of file screen by screen |
| Concatenate - file1 & file2 into file3 |
| File Operation |
|---|
| list , no details only names |
| list , details |
| move to directory |
| copy file to other/current directory |
| Delete the file |
| file |
| Change read/write/execute mode of fil |
| chown |
| move (rename ) file |
| Remove |
| Compare two files |
| Copy file file1 into file2 |
| Sort Alphabetically |
| Sort Numerically |
| Split f into n-line pieces |
| match pattern |
| Lists file differences |
| head f Output beginning of file |
| Output end of file |
| Find Files , Directories |
|---|
| find files , directories |
find . -name .log -print --- Simple find to list log files
find . -name ‘.log’ -exec rm {} ; — Simple find to find log files and delete them .
find accepts a long list of options to find the files based on different parameters such as create time , modified time , of certain size etc. Please refer to man find for more option. |
| Process Operations |
|---|
| Suspend current process |
| Interrupt processes |
| Stop screen scrolling |
| Resume screen scrolling |
| Sleep for n seconds |
| Print list of jobs |
| Kill job n |
| Remove process n |
| status process status stats |
| Resume background job n |
| Resume foreground job n |
| Exit from shell |
| User Administration |
|---|
| add a new user login |
-u is userid , if not specified system takes highest available .
-g group id should be existing in /etc/group , if not specified other or user is assigned.
-d home directory , default is to use user as the directory name under the home directory.
loginname - new login name to be created .
#useradd testlogin will create a user by the name ‘testlogin’ with all default values . |
| password Change | passwd <user> |
| alias (csh/tcsh) - Create command | alias name1 name2 |
| alias (ksh/bash) - Create alias command | alias name1=“name2” |
| alias - Remove alias | unalias name1[na2…] |
| printer | |
| Output file f to line printer | p -d printer file |
| | |
| System Status |
|---|
| Display disk quota |
| Print date & time |
| List logged in users |
| Display current user |
| Output user information |
| Display recent commands |
| Environment Variable |
|---|
| set |
| export |
| Set environment variable (csh/tcsh) to value v |
| Set environment variable (ksh/bash) to value v |
| Connectivity |
|---|
| Connecting to a remote host |
| Securely connecting to a remote host |
| Depending on ssh setting for your account you may or may not be asked a password to login. Your login/passwd will be same login password as you would use with telnet connection. |
| Communication is encrypted between two hosts so if someone intercepts your communication he will not be able to use it. |
| Copy files from/to remote host |
| ftp expects you to enter your username/passwd or if it is ftp only account it will require ftp account password . |
| put , mput ( multiple put ) command is used to transfer files to remote host. |
| get , mget ( multiple put) command is used to transfer files from remote host. |
| ftp allows some limited number of commands to be executed at ftp> prompt & summary of ftp command can be found by using ? at ftp> prompt |
| Securely copy files from/to remote host |
| Test the tcp/ip connectivity between two hosts |
| If you can ping a host the host is reachable from the machine that you are using . |
| Router/firewall configuration may prevent ping to succeed . |
| Backup and Restore |
|---|
| backup and restore using tar , TApeaRchive |
| tar xvf filename.tar --- Extract content of a tar archive |
| tar cvf filename.tar file1 file2 file3 --- Create a tar archive called filename.tar using file1, file2,file3 . |
| tar can’t copy the special files , device files .Not suitable for taking root backup. |
| backup and restore using cpio , CopyInputOutput |
| #ls |
| #find . -depth -print |
| #find . -cpio /dev/rmt/c0t0d0 --- Copy files in current directory to a tape |
| cpio can copy special files and hence useful in taking root backup containing device file. |