So far we have seen basic directory commands. Now let’s look into file commands.
First let’s see Touch Command:
This command is mainly used to create files. All kinds of files can be created using this command. By using this single command, linux system allows us to create one or more files at the same time. for example:
$touch file — this will create single file which is text file.
$touch file1.txt file2.c file3.java — this command creates three different files.
We have create file let’s look into copying, moving and deleting files.
We can copy files using cp Command.
-
Copying files :
$cp file newfile This command copies the file (file) and save it in the same directory with new name(newfile).
-
Moving files : This command is same as rename command. This is used for both moving and renaming purpose.
$mv file newfile This command moves/rename the file (file) and save it in the same directory with new name(newfile). If you specify new directory then the file will be permanently moved to the new directory with the new file name you specified.
-
Deleting files : This is used to delete files as well as directory also. $rm file2.java The file file2.java is deleted.
You can find how to delete directory from my previous article here
File Handling Commands
There are few file handling command. Let’s take look into that now.
let us see the Concatenate Files$cat command. This is used to concatenate files. By using this we can do few operations.
-
$cat filename . This will display the content from file in the terminal. $cat < filename. Both of this commands gives the same result. You an specify one or more files at the same time.
-
$cat > filename. This will create if file not exist otherwise overwrite the existing file. You have to type the content once you have run this command. Once you finished typing content then press ctrl+z to exit. once the command exits your content will be copied to the file.
-
$cat >> filename. This will also create the file if not exist otherwise this will append the content to the end of the existing file.
-
$cat file1 >> file2 This command copies the content from file1 to file2 and append it in the file2.
-
cat > — for creating file.
cat >> — for appending the files.
Share