Posts

Showing posts with the label Unix

Search for a string in multiple files

grep is a common command used on unix for searching. This is a very useful tool and provides powerful options. One such option is to search for a string in multiple files in the current directory and sub directories. The command is : grep -rl "search string" /usr -r stands for search recursively in current directory and sub directory. -l suppress the display of additional information and just outputs the file names. /usr refers to root folder under which the search happens.

How to find the Size of a folder in Unix

Its very easy to find the size of a folder in windows, where as it might be difficult to a novice user doing the same on Unix based systems. Its because the Unix file system does not show a folder size in a file listing using a short listing ls or long listing ls -l The size of 4.0k or so shown before the folder name in a long listing is not an actual size of the folder. However we are blessed with many simple commands that makes our jobs simple. One such command is du . This command stands for disk usage, represented in short as du. It recursively access all the files and sub folder under a given folder and display the size of each of this items. To display the total size of the folder in MB, GB etc., use the command du -sh Option s says du to summarize the results and do not display the details of sub folder and files Option h says display the size in human readable format i.e., K for kilobytes, M for megabytes & G for gigabytes

Delete multiple lines in Linux style Vi Editor

We often have situations were we need to modify a file using vi on Unix style file system and delete multiple lines. Here are some details and examples on how to do it. Syntax: xdd dd is the command to delete a complete row. x in the number of lines to be deleted. Examples: delete 2 lines 2dd delete 10 lines 10dd