Quick viewing(Text Mode)

Bash Cheat Sheet Level1

Bash Cheat Sheet Level1

BASH cheat sheet - Level 1 dir Directory listing. Use the –l option to –N list in long format. Display the N first lines of file(s). Without any option 10 first lines are displayed. File and directory handling commands =permission file Change the who permission of file to permission. Who –N file dir change directory to dir can be u,g or/and o (user, group or/and other) and Display the N last lines of file(s). Without any option the cd – Go back to the previous directory permission can be -,x, or/and r. 10 last lines are displayed. cd .. Go to the parent directory chmod OctalOctalOctal file cd Go to the user’s home directory (same Change the user, group and other permissions as command > file as cd ~ or cd /home/user/) defined by each octal. Redirect command output into a file. If the file exists, it • 4 read (r) is overwritten. Show the current durectory • 2 (w) • 1 execute (x) command >> file file1 file2 Copy file1 to file2. Use –r option for • 0 none (-) Redirect command output and append into file. copying a directory. chmod 754 file Read,write,execute for user, read and execute –d’;’ -f1,4 file scp source_file target_ file for group and read only for other. Cut out selected portions of each line of a file. The –d Secure copy over a network connection. A remote chmod ug=rwx file option defines the field delimiter character (here ;) source or/and target must follow that syntax: Read, write, execute for user and group. instead of the default tab character. The –f option user@IP:/home/user/path. Use –r option for copying specifies the field(s) displayed (here the first and the a directory. tar czf file.tar.gz dir Create a tar with Gzip fourth). compression of dir. rsync –L source_file target_ file tar xzf file.tar.gz Extract a tar using Gzip. file Remote file copy. Transfer just the differences between Sort lines of text file alphabetically. Use –n option to two sets of files. –L option transform symlink into gzip file Compress file and rename it to file.gz. take into account the numbers (ascending order). Use referent file/dir. Use the –d option to decompress -k N option to specified to sort according to the field N. file.gz back to file. file1 file2 Rename or move file1 to file2 if file2 is file an existing directory, moves file1 into out consecutive repeated lines in file. –u displays File information handling commands directory file2. only not repeated lines while -d displays only repeated dir Create a directory dir. ones. –l file Display the number of lines file. (-w file Delete file. Use –r option for a for the number of words, -c for the split – file prefix directory. number of characters). wc without Split file into pieces of N lines labelled by prefix. ln –s file Create symbolic link link to file. option gives these three information. split –b file Split file into pieces of N megabytes. Use k link Remove a link. file Display the content of file(s). instead of m for kylobyte and none for byte. Show disk space usage (byte). To symplify the file Display the content of file one screen "pattern" file lecture use the –h option (human readable). a . Print lines of file that match the pattern. Use the –E –h dir Show directory space usage. file Similar as more but allows backward option to interpret the pattern as a regular expression and forward movement. (see Level 2 for regular expression).

man command : display the command’s manual page Jacques Dainat - 2015 –w 60 file Break the lines to have a maximum of 60 columns width (80 by default).

Miscellaneous Display the history list with line numbers. command a command. ssh user@IP Log into a remote machine. path -name name* Find in path and sub-directory recurcively the files or directories matching name. rev file Reverse the order of characters in every line of file. file1 file2 Join specified files based on join-field and writes the result to the standard output. By default join works on the first field. join -1 2 -2 2 –a1 –a2 –o list–e "value" file1 file2 -1 2 and -2 2 allows to respectively join on the second field of file1 and the second field of file2. -a1 and –a2 option allows respectively to also include the non matching records from file1 and file2. -o list specify the fields that will be output. e.g the list 0,1.1,2.1 will display respectively the join field, the field1 of file1 and the field1 of file2. When –o option is used, the –e ‘value’ option replace any missing data fields by value. / !\ Files must be sorted by the field they will be joined to work properly.

File editing

vim Vi Improved nano emacs man command : display the command’s manual page Jacques Dainat - 2015