history
The list of previous commands may be obtained by executing the following command.man
All the Unix command information are organized in a special fashion like the following.• The user-level commands are all in Section One.
• Section Two is the Unix Application Programmer's Interface, API (ie C functions directly supported by Unix).
• Section Three is library extensions to these.
• Section Four defines devices known to Unix.
• Section Five defines common file formats.
• Sections Local and New are for stuff we have added to our local system.
If we run man command with a name first it will check for commands with that name.
Example:
man sleep
man 2 sleep
This displays details of sleep library function if available
man 3 sleep
This displays details of sleep system call if exists any.
apropos command can be used to displays names of all the commands whose manual page contains a search pattern.
Example:
apropos TERM
This displays names of the Unix commands, system calls or library functions whose manual page contains the search pattern TERM.
cal
It is used to see the calendar of any specific month or a complete year.Example -
date
To display the current date and time this command is used.Example -
$ date
Sat, Jan 14, 2017 7:22:34 PM
echo
This command is used to display a message or to evaluate shell variables.
Example -
$ echo I love cricket
I love cricket
$ echo "i love cricket"
i love cricket
$ echo $SHELL
/bin/bash
who
UNIX maintains an account of all users who are logged on to the system. It's often a good idea to know their user-ids so you can text them messages. The who command displays an informative listing of these users.
To know your own details i.e. as you logged in what's you detail the type -
$ who am i
$whoami
uname
The uname command displays certain features of the operating system running on your machine. By default it would display the name of the operating system.
Example -
$ uname
CYGWIN_NT-6.3
$ uname -r
2.6.1(0.305/5/3)
Here -r means the current release i.e. the version name.
$ uname -n
oms
Here -n means Machine name.
pwd
pwd is used to check the current directory. It stands for present working directory.
Example -
$ pwd
/cygdrive/c/Users/om/Desktop/unixstuff
cd
cd stands for current directory. You can move around in the filesystem by using cd command. When used with an argument, it changes the current directory to the directory specified as argument.
Example -
$ pwd
/cygdrive/c/Users/om/Desktop/unixstuff
$ cd backup
/cygdrive/c/Users/om/Desktop/unixstuff/backup
To move back to your previous working directory
$ pwd
/cygdrive/c/Users/om/Desktop/unixstuff/backup
$ cd ..
$ pwd
/cygdrive/c/Users/om/Desktop/unixstuff
mkdir
This command is used to create a new directory.
Example -
$ mkdir programs
This creates programs directory inside your present working directory.
$ mkdir programs/abc
This creates abc directory inside programs which is inside your present working directory.
$ mkdir util/kkk
mkdir: cannot create directory ‘util/kkk’: No such file or directory
As we noticed here that util directory was not there inside our current working directory so it gives an error.
rmdir
This is used to remove empty directory only.
Example -
$ rmdir programs
rmdir: failed to remove 'programs': Directory not empty
$ rm -r programs
It is used to delete any directory having files in it.
ls
It is used to obtain a list of all filenames in the current directory.
Example -
$ ls
2000 awk_example2.awk bak cal.jpg cal3.jpg customers emp.sh employee.txt my.sh
$ ls -x (Here -x is used to display the output in multiple columns)
2000 4304 abc awk_example2.awk awk_example2.sh
backup bak bak1 bookdetails.txt cal.jpg
cal1.jpg cal2.jpg cal3.jpg clerk Column2.sh
customers Document.text emp emp.sh empfile1.txt
empfile2.txt employee.txt manager my.awk my.sh
nohup.out one product typescript
$ ls -F
-F is used to identify the directories and executables. When you run the above code you notice some changes in the file name where * indicates that the file contains executable code and / refers to a directory.
The options related to ls which performs different task are as follows -
- -x ( Multicolumnar output )
- -F ( Marks executables with *, directories with / and symbolic links with @ )
- -a ( Shows all filenames beginning with a dot including . and .. )
- -R ( Recursive list )
- -r ( Sorts filenames in reverse order )
- -l ( Long listing )
- -d dirname ( Lists only dirname if dirname is a directory)
- -t ( Sorts filenames by last modification )
- -lt ( Sorts listing by last modification time)
- -u ( Sorts filenames by last access time )
- -i ( Displays inode number )
cat
The cat command is used to create, read, append a file.
Example -
To create a file and insert data into it.
$ cat > abc.txt
rakesh
kumar
prasad
Note : After you are done with data typing to save it into that file type CTRL+Z
To read from a file
$ cat abc.txt
rakesh
kumar
prasad
$ cat < abc.txt
rakesh
kumar
prasad
To append data into a file
$ cat >> abc.txt
hello
learners
$ cat abc.txt
rakesh
kumar
prasad
hello
learners
To read data from a file with its respective line number
$ cat -n abc.txt
1 rakesh
2 kumar
3 prasad
4 hello
5 learners
cp
This cp command is used to copy the exact image of an file to a specific location.
Example -
$ cp abc.txt xyz.txt
$ cp abc.txt backup/xyz.txt ------ It copies xyz.txt file inside backup directory
$ cp -i abc.txt xyz.txt
cp: overwrite 'xyz.txt'? y
The above -i option warns the user before overwriting the destination file. If xyz.txt exists then it will prompt for a response else it will create that file.
$ cp -R backup bakk
-R is used to make an image of a directory.
No comments:
Post a Comment