

Versions An example of GNU Grep in operation.

#CAT AND GREP COMMAND IN LINUX MANUAL#
Unix grep(1) manual page at, DESCRIPTION section.2.1 Command-line Options at grep manual, gnu.org.-regexp=pattern, in addition to -e pattern.-o: Output the matched parts of a matching line.Ĭommand-line options aka switches of GNU grep, beyond the bare-bones grep:.-s: Suppress error messages about nonexistent or unreadable files.-h: Output matching lines without preceding them by file names.-b: A historical curiosity: precede each matching line with a block number.-n: Precede each matching line with a line number.-c: Output count of matching lines only.* which can stand for anything in a file's name and \(txt\|jpg\) which yields either txt or jpg as file endings.Ĭommand-line options aka switches of grep: Grep command can be piped with any suitable command and can show us those lines which is provided as a argument to grep.īelow you can see argument to grep is 'watching' so cat provides all the lines to grep and grep filterout all lines but "Thanks for watching" as it is contains 'watching'.The regex here is made up from. $ echo "Thanks for watching" > welcome.txt $ echo "This is Shell Scpriting Tutorial" > welcome.txt $ echo "Welcome to TuneToTech" > welcome.txt To understnd this lets insert some lines to a file. We can use pipe to execute one command after another where the output from first command is the input to second command. This can be change using below command(actually it is an environment variable). As you can see so far the prompt name is "$". History command is useful to see all perviously executed commands.Ĭhange prompt name. rw-r-r- 1 tjman tunetotech 75 Apr 24 13:49 welcome_2.txtĭrwxr-xr-x 2 tjman tunetotech 4096 Apr 24 14:11 folder1 Mv can be used to rename a file/directories or we can move the file/directories to another folder. rw-r-r- 1 tjman tunetotech 75 Apr 24 14:05 welcome_copy.txtĭrwxr-xr-x 2 tjman tunetotech 4096 Apr 24 14:05 folder1_copy rw-r-r- 1 tjman tunetotech 75 Apr 24 13:49 welcome.txtĭrwxr-xr-x 2 tjman tunetotech 4096 Apr 24 14:05 folder1 r use it for folders to copy internal recursive files, otherwise folder copy will not work. You can make a copy of a file or directory using cp command. Rm: cannot remove ‘folder1’: Is a directoryĬP: cp refers to copy. rw-r-r- 1 tjman tunetotech 22 Apr 24 13:03 x.txtĭrwxr-xr-x 2 tjman tunetotech 4096 Apr 24 13:25 folder1 rw-r-r- 1 tjman tunetotech 0 Apr 24 13:03 x.txt r, -R remove directories and their contents recursively To delete any file/directories, we can use rm command. As we just now insert some text on x.txt, we can see it using cat. $ echo 'Welcome to TuneToTech' > x.txtĬat is veryful to see every thing inside a files. This can also be used to insert some text on a file as below. Then you can see timestamp and lastly the file name at the extream right.Įcho will print whatever you write after it except quote. Next numeric values the size of the files in byte. Tjman is the owner of the file and the files is belong to tunetotech group. so on, these are the number of hard link associated with the file. We will discuss it in great details in next post. If it is 'd' means a directory and '-' refers to a file. The first word is indicating a file or a directory. Note: Lets understnd what the above output actually indicates. rw-r-r- 1 tjman tunetotech 0 Apr 24 12:04 x.txt

rw-r-r- 1 tjman tunetotech 0 Apr 24 12:04 y.txt rw-r-r- 1 tjman tunetotech 0 Apr 24 12:04 z.txt c.txt x.txt y.txt z.txtĭrwx- 9 tjman tunetotech 4096 Apr 24 11:58. t sort content by recently modified first a to show all files including hidden files Ls is probably the most used command in Linux to see the files and directories persent in current directory. ("dot") then it will be a hidden file.** LS(list directory contents): **Note: If you create a file with name stating with. Using this command you can create a directory on your present directory. It prints the absolute path of directory where you are in right now. Open a Linux terminal and play with these commands. These are most widely used Linux command which we need almost every time we want to do anything on Linux.
