Centos File System Commands

From rbachwiki
Revision as of 14:40, 5 February 2019 by Bacchas (talk | contribs)
Jump to navigation Jump to search

File Command displays type of file

file me.text
#output
ASCII text

Wildcard Metacharacters

* Matches 0 or more characters in a filename
? Matches 1 character in a filename
[aegh]  Matches 1 character in a filename—provided this character is either an a, e, g, or h
[a-e]  Matches 1 character in a filename—provided this character is either an a, b, c, d, or e
[!a-e] Matches 1 character in a filename—provided this character is NOT an a, b, c, d, or e

Viewing Text Files

cat -n file.txt
# will display the file with line numbers
tac file.text
#will display the file in reverse

The head command displays the first 10 lines (including blank lines) of a text file to the terminal screen but can also take a numeric option specifying a dif- ferent number of lines to display.

head -3

tail command can be used to display the end of text files. By default, the tail command displays the final 10 lines of a file, but it can also take a numeric option specifying the number of lines to dis- play on the terminal screen

tail -3

The more command gets its name from the pg command once used on UNIX systems. The pg command displayed a text file page by page on the terminal screen, starting at the begin- ning of the file; pressing the spacebar or Enter key displays the next page, and so on.

more file.txt

the less command is named for doing more than the more command (remember that “less is more,” more or less). Like the more command, the less command can browse the contents of a text file page by page by pressing the spacebar and line by line by pressing the Enter key; however, you can also use the cursor keys on the keyboard to scroll up and down the contents of the file. Displaying the Contents of Binary Files

strings /bin/echo | more
# strings command piped to the more command

od command, which displays the contents of the file in octal format (numeric base 8 format).

od filename | head -5
# od command piped to head to display 5 lines

Grep Command requires a minimum of two arguments, search are case sensitive

grep "find this" filename.txt
grep -i "find this" filename.txt 
# the -i option makes it case insensitive

To view lines that contain the word “toe” or “the” or “tie,” you can enter the following command:

grep "t.e" filename.txt

To view lines that start with the word “I,”

grep "^i" filename.text

You can HARD LINK a file an unlimited number of times, but the files must reside on the same file system

ln file1 file2

Symbolic Link (Shortcut)

ln -s file1 file2
ls -l # view the symbolically linked filename after creation