File Handling Linux Commands
Linux has become most prominent operating system and for effective use of Linux system we should know certain basic file handling commands to perform our day-to-day operations in most efficient way. Here we have listed some of the most important and interesting File Handling commands which are ordered in categories wise to improve your Linux skills.
Easy File Viewing and Editing
We use gedit tool in Linux which is similar to notepad or WordPad in windows and it also got tabbed viewing of text files. But at the same time we should get familiar with using commands and this most will make that easier. Basic Text editors in Linux are Vim and Emacs which supports syntax highlighting and helps you a lot in programming skills. Some of the commands features are discussed here
Vim is easy to use and powerful text edit intended for beginner and advanced users. It has lot of in featured commands for text editing for simple task like copy, paste and some advanced commands like searching text, find and replace option.
[fasil@smashtech ~]# vim smashtech.txt |
The above command will open the text file in the Vim editor and you can easily edit the text file and save it by entering the Escape key -> :w and to quit the editor Escape key -> :q .To know more about Vim commands download this cheat sheets.
Emacs is most powerful editor intended for advanced users. Prominent use of emacs is multiple window use. We can easily open almost four to five windows with horizontal or vertical view and helps you alot in manipulating multiple files.
[fasil@smashtech ~]# emacs smashtech.txt |
The above command will open the text file in the Emacs editor and once editing is completed. Press ctrl+x+s to save file and to quit editor ctrl+x+c.To know more about emacs commands download this cheat sheet.
cat command will list the content of the file in the terminal .This option is limited to view files having only few lines since you have to scroll back to view the text if it is a large file.
[fasil@smashtech ~]# cat smashtech.txt This text is displayed using cat command |
Simple command to view text files and to list the files in compressed archive like tar or zip.
[fasil@smashtech ~]#less smashtech.tar.gz -rw-rw-r-- root/root 326 2009-03-04 13:48:50 /Documentation/RelNotes-1.5.3.1.txt -rw-rw-r-- root/root 1931 2009-03-04 13:48:50 Documentation/RelNotes-1.5.3.2.txt -rw-rw-r-- root/root 896 2009-03-04 13:48:50 /Documentation/RelNotes-1.5.3.3.txt -rw-rw-r-- root/root 1208 2009-03-04 13:48:50 /Documentation/RelNotes-1.5.3.4.txt -rw-rw-r-- root/root 3376 2009-03-04 13:48:50 |
Checking file size and disk usage
Simple commands like 'list' can be used to check the file size or folder size but the Linux has some more powerful commands to do so.
df - report filesystem disk space usage is simple command to check the disk space in all partitions of harddisk.
[Fasil@smashtech ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda6 19.7G 18.1G 1.1G 89% / |
du - estimate file space usage of all files and folders
[Fasil@smashtech ~]# du -sh . 602M . |
Simply Copy/rename and move files
Copying, moving and deleting files like never before, Simply saying you can delete files and folders very fast in command prompt then using mouse in GUI.But here is a caution although Linux is more powerful it does not have an undo command and if you delete a file/folder my mistake its loss. There are some methods to recover it but redundancy will be lost. cp - Copy files from source location to destination
[Fasil@smashtech ~]# cp file1.txt file2.txt The above command will copy file1 as file2 text file [Fasil@smashtech ~]# cp -a smashtech fasil the above command will copy the folder smashtechtech as fasil |
mv-Move a file from original location to final location
[Fasil@smashtech ~]# mv file1.txt file2.txt The above command will move/rename file1 as file2 text file [Fasil@smashtech ~]#mv -a smashtech fasil the above command will move contents of the folder smashtech to fasil |
rm-Remove a file or folder
[Fasil@smashtech ~]# rm file1.txt The above command will delete file1 [Fasil@smashtech ~]#rm -rf smashtech the above command will delete the folder smashtech |
Compressing and Decompressing Files and Folders
The most interesting usage in Linux commands are compressing the text files in more efficient and effective way and some of the compressing and decompressing commands are shown here.
tar- This command is used for both compressing and extracting
[Fasil@smashtech ~]# tar -cvf filename.tar folder/ The above command will create a tar archive with name.tar and folder is archived Fasil@smashtech ~]# tar -cvzf filename.tar.gz folder/ The above command will create a gzip archive with name.tar and folder is archived Fasil@smashtech ~]# tar -cvjf filename.tar.bz2 folder/ The above command will create a bzip2 archive with name.tar and folder is archived |
[Fasil@smashtech ~]# tar -xvf filename.tar The above command will extract the content of the tar archive with name.tar Fasil@smashtech ~]# tar -cvzf filename.tar.gz folder/ The above command will extract the content of a gzip archive Fasil@smashtech ~]# tar -cvjf filename.tar.bz2 folder/ The above command will extract the content of the bzip2 archive |
No comments:
Post a Comment