Shell Commands
Ctrl + C
to cancel commandCtrl + A
to move the cursor to the beginning of the lineCtrl + E
to move the cursor to the end of the lineCtrl + U
to clear the line to the beginningOpt + Click
to move the cursor to the desired locationclear
or Ctrl + L
to scroll up to clear the screenCmd + K
to clear the screenexit
or Ctrl + D
to exit the current sessionCtrl + A
and Ctrl + K
to delete the current line in the terminalecho "Hello, world" > sample.txt
is used to set the contents of sample.txt
to Hello, world
echo "Hello, world" >> sample.txt
is used to append Hello, world
to the contents of sample.txt
cat sample.txt
is used to display the contents of sample.txt
head sample.txt
is used to display the first 10 lines of sample.txt
tail sample.txt
is used to display the last 10 lines of sample.txt
diff sample.txt sample2.txt
is used to display the difference in contents between the specified filesless sample.txt
is used to view sample.txt
in a more interactive way/search
is used to search for a substring when viewing files using less
n
or N
is used to find the next or previous match respectively when searching using less
grep substring filename -i
is used to search for substring
in filename
. -i
represents case-insensitivitygrep -ri substring directory/
is used to serach for substring
in all files recursively found in the directory directory
ls *.txt
is used to display all files ending in .txt
in the current directoryls -l
is used to display all files with additional information such as size, permissions, etcls -r
is used to reverse the order in which the files are displayedls -t
is used to display most recently modified files firstls -a
is used to display all files (i.e. visible and hidden files)ls -d
is used to display all directoriespwd
prints working directoryfind . -name "*.txt"
is used to display all files ending in .txt
in the current directorymv currentFileName newFileName
is used to rename a filecp file.txt file-copy.txt
is used to copy a filerm filename
is used to remove a filerm -f
is used to force remove a file without prompting for confirmationmv *.txt text_files/
is used to move all files ending in .txt
to the directory text_files
cp filename .
is used to copy filename
to the current directorycp -r ../text_files .
is used to copy the directory text_files
to the current directory. -r
means recursively.cp - r ../text_files/ .
or cp -r ../text_files/* .
is used to copy the contents of text_files
to the current directoryrmdir directoryname
is used to remove an empty directoryrm -rf directoryname/
is used to remove a directorytab
is used to auto complete file namestab + tab
is used to display all the possible auto complete options!!
is used to run the previous command!curl
is used to run the previous command starting with curl
Ctrl + R
is used to interactively search for previously ran commandswc filename
is used to display word count information|
is used to connect two commands (e.g. head sample.txt | wc
)cd -
is used to navigate back to the previous directory;
is used to seperate multiple commands&&
is used to seperate multiple commands but only executes a command if the previous command was successfulman command
is used to display a manual for command