Skip to main content

Handy Linux Commands

Submitted by amitsedai on
Split: Split a text file in half (or any percentage) on Ubuntu Linux The following command splits access.log files into multiple files with 6000 lines each split -l 6000 access.log
Split files into size of 5M each split --bytes 5M --numeric-suffixes --suffix-length=3 foo.mysql last_part.mysql
Diff : Get Difference between files and folders Following command provides recursive difference diff -r dir1/ dir2/
Sed: To delete lines matching a string in a file sed --in-place '/url_alias/d' some_db.mysql
Deletes all lines matching url_alias string in some_db.mysql file Replace strings in file with another: sed -i 's/old-word/new-word/g' *.txt
Replaces old-word with new-word with all txt extension files in the directory. i is for ignore case. Grep: Used for string search across files in directories. The following handy command searches for specific string in a specified file recursively in the location provided. grep -rn search_string -A 1 -B 3 --include=settings.php /srv/www/
where location to recursively search is /srv/www/ and the string is searched only on a specific file settings.php. Also the option -A 1 specifies to print one line above the line where the string is found in the file and -B 3 specifies printing 3 lines below the searched string line. Additionally grep comand can be combined with the find command as follows find /srv/www/ -name settings.php -exec grep -n -A 1 -B 3 -H search_string {} \;
du: Disk Usage Display the disk usage for all one level of directories du -h --max-depth=1
-- Source http://www.howtogeek.com/howto/ubuntu/split-a-text-file-in-half-or-any-percentage-on-ubuntu-linux/ http://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/ http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/ http://linux.about.com/library/cmd/blcmdl1_du.htm

Technologies