Using &&
as connector between commands
Example:
$ git add -A && git commit -m "Add About page"
or
$ git add -A ; git commit -m "Add About page"
The difference is that commands separated by && run only if the previous command succeeded. In contrast, with ; all the commands will be run no matter what, which will cause an error in the likely case that subsequent commands depend on the results of the ones that precede them.
Example piping the result between commands
$ head sonnets.txt | wc
Or piping the result to file
$ ping learnenough.com > learnenough.log
Or append to file
$ ping learnenough.com >> learnenough.log
Hidden files
Hidden files and directories are identified by starting with a dot .
$ man <command>
Example:
$ man tail
$ pwd
Change to home directory
$ cd ~
Change to previous directory
$ cd -
$ ls -l -a
or
$ ls -la
-l option: show by list -a option: show hidden files
List with wildcard
$ ls *.txt
List with long form
$ ls -rtl
View head of the file
$ head <file>
View end of the file
$ tail <file>
View all file
$ less <file>
- up & down arrow keys: Move up or down one line
- spacebar: Move forward one page
- ⌃F: Move forward one page
- ⌃B: Move back one page
- G: Move to end of file
- 1G: Move to beginning of file
- /: Search file for string /rose
- n: Move to next search result
- N: Move to previous search result
- q: Quit less
Find all occurrences 'time=3.40' in file 'learnenough.log'
grep time=3.40 learnenough.log
Find string from command line result. Ex: find the process 'spring' in running processes
$ ps aux | grep spring
$ find . -name '*.txt'
$ echo "hello" >> a.txt
If the file is not existing, it would be created. But be careful, using only one > would clear all existing lines of file:
$ echo "again" > a.txt
$ wc <file>
$ mkdir -p <folder stack>
Example:
$ mkdir -p repos/website
The directory repos
is created, and the directory website
is also created which is inside repos
$ touch <filename>
$ diff <file1> <file2>
$ ps aux
with sorting
$ top
$ kill <process id>
or kill a process by name
$ pkill -f <process name>
$ ping <domain/IP>
$ clear
$ history
Save history into a file
$ history > a.txt
$ which <command>
Example:
$ which git