Linux Unix Basic Commands
Commands
pwd Command
Show Current Direcctory
$ pwd /home/linuxize
cal command
Displays the calendar of the current month.
$ cal July 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
echo command
This command will echo whatever you provide it.
$ echo "linoxide.com" linoxide.com
The ‘echo’ command is used to display the values of a variable. One such variable is ‘HOME’. To check the value of a variable precede the variable with a $ sign.
$ echo $HOME /home/raghu
Date Command
Displays current time and date.
$ date Fri Jul 6 01:07:09 IST 2012
If you are interested only in time, you can use date +%T (in hh:mm:ss):
$ date +%T 01:13:14
tty command
Displays current terminal.
$ tty /dev/pts/0
whoami command
This command reveals the user who is currently logged in.
$ whoami raghu
id command
This command prints user and groups (UID and GID) of the current user.
$ id uid=1000(raghu) gid=1000(raghu) groups=1000(raghu),4(adm),20(dialout),24(cdrom),46(plugdev),112(lpadmin),120(admin),122(sambashare)
By default, information about the current user is displayed. If another username is provided as an argument, information about that user will be printed:
$ id root uid=0(root) gid=0(root) groups=0(root)
clear command
This command clears the screen.
$ clear
help option
With almost every command, ‘--help’ option shows usage summary for that command.
$ date --help Usage: date [OPTION]... [+FORMAT] or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] Display the current time in the given FORMAT, or set the system date.
whatis command
This command gives a one line description about the command. It can be used as a quick reference for any command.
$ whatis date
date (1) - print or set the system date and time
$ whatis whatis
whatis (1) - display manual page descriptions
Manual Pages
‘--help’ option and ‘whatis’ command do not provide thorough information about the command. For more detailed information, Linux provides man pages and info pages. To see a commands manual page, man command is used.
$ man date
The man pages are properly documented pages. They have following sections:
NAME: The name and one line description of the command.
SYNOPSIS: The command syntax.
DESCRIPTION: Detailed description about what a command does.
OPTIONS: A list and description of all of the commands options.
EXAMPLES: Examples of command usage.
FILES: Any file associated with the command.
AUTHOR: Author of the man page
REPORTING BUGS: Link of website or mail-id where you can report any bug.
SEE ALSO: Any commands related to the command, for further reference.
With -k option, a search through man pages can be performed. This searches for a pattern in the name and short description of a man page.
$ man -k gzip gzip (1) - compress or expand files lz (1) - gunzips and shows a listing of a gzip d tar d archive tgz (1) - makes a gzip d tar archive uz (1) - gunzips and extracts a gzip d tar d archive zforce (1) - force a .gz extension on all gzip files
Info page
Info documents are sometimes more elaborate than the man pages. But for some commands, info pages are just the same as man pages. These are like web pages. Internal links are present within the info pages. These links are called nodes. Info pages can be navigated from one page to another through these nodes.
$ info date
Changing Directories Command
$ cd [path-to-directory]
Change the current working directory to the directory provided as argument. If no argument is given to ‘cd’, it changes the directory to the users home directory. The directory path can be an absolute path or relative to current directory. The absolute path always starts with /. The current directory can be checked with ‘pwd’ command (remember?):
$ pwd /home/raghu $ cd /usr/share/ $ pwd /usr/share $ cd doc $ pwd /usr/share/doc
In the first ‘cd’ command, absolute path (/usr/share) is used, and with second command, relative path (doc) is used.
Listing File And Directories Command
$ ls [files-or-directories]
List files and/or directories. If no argument is given, the contents of current directory are shown.
$ ls
example file1.txt file2.txt file3.txt
If a directory is given as an argument, files and directories in that directory are shown.
$ ls /usr
bin games include lib lib64 local sbin share src
‘ls -l’ displays a long listing of the files.
$ ls -l total 4 drwxr-xr-x 2 raghu raghu 4096 2012-07-06 12:52 example -rw-r--r-- 1 raghu raghu 0 2012-07-06 12:52 file1.txt$ ls -la odesk total 16 drwxr-xr-x 4 raghu raghu 4096 2012-07-06 13:46 . drwxr-xr-x 11 raghu raghu 4096 2012-07-06 13:15 ..
If you want to see the properties of a directory instead of the files contained in it, use -d (with -l) option:
$ ls -ld odesk/ drwxr-xr-x 4 raghu raghu 4096 2012-07-06 13:46 odesk/
Creating files and directories
mkdir command
To create a directory, the ‘mkdir’ command is used.
$ mkdir example $ ls -l total 4 drwxr-xr-x 2 raghu raghu 4096 2012-07-06 14:09 example
Touch command
For creating an empty file, use the touch command.
$ touch file1 file2 file3 $ ls -l total 4 drwxr-xr-x 2 raghu raghu 4096 2012-07-06 14:09 example -rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file1
If a file already exists, touch will update its time stamp. There are a lot of other methods to create a new file, e.g. using a text editor like vi or gedit, or using redirection. Here is an example of creating a file using redirection:
$ ls -l /usr > usrlisting $ ls -l total 8 drwxr-xr-x 2 raghu raghu 4096 2012-07-06 14:09 example -rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file1 -rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file2 A file named usrlisting is created in this example.
copy command
$cp source destination
Copy files and directories. If the source is a file, and the destination (file) name does not exit, then source is copied with new name i.e. with the name provided as the destination.
$ cp usrlisting listing_copy.txt$ cp listing_copy.txt example/$ cp -r example /tmp/expertslogin/$ ls -l /tmp/expertslogin total 4 drwxr-xr-x 2 raghu raghu 4096 2012-07-06 16:12 example
move command
$ mv source destination
Move files or directories. The mv command works like cp command, except that the original file is removed.
But, the mv command can be used to rename the files (or directories).
$ mv listing_copy.txt usrcopy
Here, listing_copy.txt is moved with the name usrcopy in the same directory (or you can say that it has been renamed).
To remove or Delete
$ rmdir
rmdir command removes any empty directories, but cannot delete a directory if a file is present in it.
To use ‘rmdir’ command, you must first remove all the files present in the directory you wish to remove (and possibly directories if any).
To remove files and directories
$ rm files|directories$ rm file2$ rm file.txt
cat command
The cat command is actually a concatenator but can be used to view the contents of a file.
$ cat /etc/passwd
THANKS FOR READING
Comments
Post a Comment