In my previous article i have explained the Unix Directory commands with real world example and how to create file in multiple ways in unix.In this article i will explain Unix File Commands with examples.File is nothing but collection of information.The files are very much useful in any operating system.In Unix operating system everything is considered as file ; unix directory is also considered as one type of file.There are following types of files in unix:
1.Regular/ Ordinary Files
3.Device Specific Files
4.Links
5.Named Pipes
6.Sockets
For working on such files we need to use following different Unix File Commands:
WC command is very useful and most use File Commands in unix which is used to count the words,total characters in file,total byte count.WC stands for ‘Word Count’ which counts total number of lines,words or characters in the specific file.
Generic Syntax of WC Command :
. $ wc File_Name option
1.1. To count No of lines :
$ wc – l File_Name
The above command is used to calculate the no of lines in specific file.
Example :
$ wc – l Amit.txt
100
1.2. To count No of words in file :
$ wc – w File_Name
The above command is used to calculate the no of lines in specific file.
Example :
$ wc – w Amit.txt
1000
1.3. To count No of characters in file :
$ wc – c File_Name
The above command is used to calculate the no of characters in file.
Example :
$ wc – c Amit.txt
10000
1.4. To count No of lines and words in file :
$ wc –lw File_Name
The above command is used to calculate line and word for specific file.
Example :
$ wc –lw Amit.txt
100
1000
1.5. To count No of words and characters in file :
$ wc –lw File_Name
The above command is used to calculate line and word for specific file.
Example :
$ wc –lw Amit.txt
1000
10000
1.6. To count No of words and characters in file :
$ wc –lc File_Name
The above command is used to calculate line and character for specific file.
Example :
$ wc –lc Amit.txt
100
10000
CP command in unix is used to copy the file from source path to target path.CP command is used to copy the file content from source file to target file.Source file must be existing file and target file may be a new file/existing file.
Syntax:
$ cp Source_File Target_File
Example:
$ cp unix.txt linux.txt
This command will copy all contents in file unix.txt to linux.txt.
It compares 2 files character by character, if no output then files are same otherwise the files are not same & output is shown.
Syntax :
$ cmp File_1 File_2
Example :
$cmp a1 a2 (If character are same no result)
Step 1 :
$ cat>A1
Hello
Ctrl+d
$ cat>A2
Hello
Ctrl+d
$ cat> A3
Helo
Ctrl+d
Step 2:
$ cmp A2 A3
Ls command is most commonly used unix command to show the list of files in that working directory.
Syntax:
$ls [option]
To list all Files and Directories :
It list current directory all files & sub – directories in ascending order based on ASCII Values.
Example :
$ls
Amit pradnya.txt unix.txt
To list all files with hidden files/directories :
Following option is used to show the files with hidden files and folders in specific directory.
$ ls -a
To list all files in reverse order(Descending) :
$ ls -r
To list all files recursively :
$ ls – R
To list all files based on date and time of creation :
$ ls – t
5.RM command to remove files :
RM command is used to remove file on specific path of unix.
Syntax :
$rm File_Name
Example :
$rm Amit.txt
If file is removed properly it will produce no output on prompt.
5.1.To remove File with permission :
If user wants to remove file with its permissions use -i option.
Syntax :
$ rm –I file_name
Example :
$ rm –I Amit.txt
5.2.To remove File forcefully:
If user wants to remove file forcefully use -f option. IF using simple method file is not removing then try this method.
Syntax :
$ rm –f file_name
Example :
$ rm –f Amit.txt
5.3.To remove multiple files:
User can remove multiple files at a same time.
Syntax :
$ rm file1 file2 ……File_N
Example :
$ rm Amit.txt unix.tx Linux.txt
The above statement will remove 3 different files Amit.txt,unix.txt and Linux.txt.
Hope this article is useful to users who are working on unix.If you like this article dont forget to comment in comment section.
In my previous articles I have given the roles and responsibilities of L1,L2 and L3…
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…
In this series we are starting with Roles and responsibilities of L1 support engineer .…