Linux Commands to know
PWD -> Present working directory
history - check all previous commands executed
Copy filescp seasonal/summer.csv backup/summer.bck ( this copies seasonal/summer.csv file to backup dir and file as summer.bck)
Move Filesmv seasonal/spring.csv seasonal/summer.csv backup/ ( moves multiple files to backup dir)
Rename Files mv can also be used to rename files ( this overwrites existing files) mv course.txt old-course.txt
Delete filesrm filename
Delete directoryrmdir dirname ( directory has to be empty b4 deleting)
Make Directorymkdir dir name
View filescat filename
View Several Files less dir/demo.csv dir/demo2.csv:n (colon and a lower-case 'n') to move to the next file, :p to go back to the previous one, or :q to quit.
display top n head -n 3 seasonal/summer.csv
display bottom ntail -n 5 dir/filename
How can I list everything below a directory?ls -R -F
get help for a command?man command name
select columns from a filecut -f 3-6,8 -d . filenamewhich means "select columns3 through 6 and columns 8, using comma as the separator". cut uses -f (meaning "fields") to specify columns and -d (meaning "delimiter") to specify the separator.
Check history of all commands run on terminalhistory
select lines containing specific valuesgrep keyword dir/filename grep can search for patterns as well -c: print a count of matching lines rather than the lines themselves -h: do not print the names of files when searching multiple files -i: ignore case (e.g., treat "Regression" and "regression" as matches) -l: print the names of files that contain matches, not the matches -n: print line numbers for matching lines -v: invert the match, i.e., only show lines that don't match
Store a command's output in a new file head -n 5 season/summer.csv > top.csv
Combine commands using | (pipe operator)cut -d , -f 2 seasonal/summer.csv | grep -v Tooth
count the records in a filewc , wc (short for "word count") prints the number of characters, words, and lines in a file. You can make it print only one of these using -c, -w, or -l respectively.
specify many files at once , head -n 3 dir/.csv
sort lines of textsort sort puts data in order. By default it does this in ascending alphabetical order, but the flags -n and -r can be used to sort numerically and reverse the order of its output, while -b tells it to ignore leading blanks and -f tells it to fold case (i.e., be case-insensitive).
remove duplicate linesuniq use uniq -c to display unique lines with a count of how often each occurs rather than using unique
Stop running a programcltrl + c
How to edit a filenano filename Ctrl + K: delete a line. Ctrl + U: un-delete a line. Ctrl + O: save the file ('O' stands for 'output'). You will also need to press Enter to confirm the filename! Ctrl + X: exit the editor.
Save steps of commands to a filehistorytail -n 3 | history > steps.txt
Save Commands to re-run laterput the commands in a file and name it with .sh extension (filename.sh)run it using bash filename.sh