Bash Command Quick Reference
ls => list of files in a folder / directory
$ ls
List of files with permission (long format)
$ ls -l
List of all files in a directory
$ ls -a
cd => change directory
$ cd <folder>
Go back to home
$ cd
Or
$ cd ~
Create or make a directory or folder
$ mkdir Junk
Locate or search a file.
$ locate filename
To update system db
$ sudo updatedb
"Which" command is used to find other commands
$ which cal
(cal represents calendar command)
Use "history" command to display the history of all the commands you used
$ history
To know what the command does (use whatis command)
$ whatis cal
Copy a file use cp command (cp sourcefile newfile)
$ cp ~/.bashrc bashrc
Move a file (this overwrites and deletes the source file)
$ mv sourcefile targetfile.bash
Remove a file (rm command)
Cat command - "cat" command is used to read the file and display in the monitor
$ cat file1 file2
(merge file1 and file 2 content and shows in the screen)
$ cat >> file2
Append text
$ cat > file3
(new file)
$cat
Nano =>
$ nano
Copy the list of files and access from root directory and write it to a file called out.txt
$ ls -al / > out.txt
To see the output of a file used below command
$ less out.txt
Sudo => if we need to run a command with elevated privileges / access.
$ sudo updatedb
$ sudo -s
Exit
$ su - cindy
(This command will switch user to cindy and do necessary work)
$ exit
logout
This appends the output to all.txt
cat *.txt >> all.txt
This overwrites all.txt
cat *.txt > all.txt
Kill a process or application
$ killall firefox