pwd
cd [directory]
cd
or cd ~
cd -
Example:
$ pwd
/home/user/documents
$ cd ..
$ pwd
/home/user
$ cd -
/home/user/documents
ls
ls -a
ls -l
ls -lh
Example:
$ ls -lh
total 20K
drwxr-xr-x 2 user user 4.0K Jul 19 10:00 Desktop
drwxr-xr-x 2 user user 4.0K Jul 19 10:00 Documents
drwxr-xr-x 2 user user 4.0K Jul 19 10:00 Downloads
touch [filename]
mkdir [dirname]
mkdir -p [path/to/dirname]
Example:
$ touch newfile.txt
$ mkdir newdir
$ mkdir -p deeply/nested/directory
cp [source] [destination]
cp -R [source] [destination]
mv [source] [destination]
rm [filename]
rmdir [dirname]
rm -r [dirname]
Example:
$ cp file1.txt file2.txt
$ mv file2.txt newname.txt
$ rm newname.txt
$ rm -r olddir
chmod [permissions] [filename]
chown [user]:[group] [filename]
Example:
$ chmod 644 myfile.txt
$ chown user:group myfile.txt
cat [filename]
less [filename]
head [filename]
tail [filename]
Example:
$ cat myfile.txt
This is the content of myfile.txt
$ tail -n 5 logfile.log
grep [pattern] [filename]
grep -r [pattern] [directory]
grep -c [pattern] [filename]
Example:
$ grep "error" logfile.log
$ grep -r "TODO" ./src
nano [filename]
vim [filename]
Example:
$ nano config.txt
$ vim script.sh
ps aux
ps
pstree
Example:
$ ps aux | grep nginx
$ pstree -p
kill [PID]
pkill [process_name]
kill -9 [PID]
Example:
$ kill 1234
$ pkill firefox
[command] &
jobs
fg [job_number]
bg [job_number]
Example:
$ long_running_command &
[1] 1234
$ jobs
[1]+ Running long_running_command &
$ fg 1
Ctrl + C
Ctrl + Z
Ctrl + L
Ctrl + R
Ctrl + A
Ctrl + E
Ctrl + W
Ctrl + U
alias [name]='[command]'
alias
Example:
$ alias ll='ls -lh'
$ alias
ll='ls -lh'
function_name() {
# Function body
}
Example:
$ greet() {
> echo "Hello, $1!"
> }
$ greet Alice
Hello, Alice!
history
!!
![n]
!string
Example:
$ history
1 ls
2 cd documents
3 grep "error" log.txt
$ !grep
grep "error" log.txt
*
?
[...]
[!...]
Example:
$ ls *.txt
file1.txt file2.txt
$ ls doc?ment.txt
document.txt
$ ls file[1-3].txt
file1.txt file2.txt file3.txt
command > file
command >> file
command 2> file
command &> file
Example:
$ echo "Hello, World!" > greeting.txt
$ ls non_existent_file 2> error.log
command1 | command2
Example:
$ ls -l | grep ".txt"
$ cat large_file.txt | less
variable_name=value
$variable_name
export variable_name=value
Example:
$ name="John"
$ echo "Hello, $name!"
Hello, John!
$ export PATH="$PATH:/new/path"
env
echo $VARIABLE_NAME
Example:
$ echo $HOME
/home/user
$ echo $PATH
/usr/local/bin:/usr/bin:/bin
nano ~/.zshrc
source ~/.zshrc
Example of adding to ~/.zshrc:
# Set custom prompt
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f$ '
# Add custom alias
alias update='sudo apt update && sudo apt upgrade -y'
setopt extended_glob
*(.(txt|log))
*(/)
*(@)
Example:
$ ls *(.(txt|log))
file1.txt file2.txt error.log
Tab
for suggestionssetopt correct
Example:
$ grpe "pattern" file.txt
zsh: correct 'grpe' to 'grep' [nyae]?
pushd [directory]
popd
dirs -v
Example:
$ pushd /var/log
$ pushd /etc
$ dirs -v
0 /etc
1 /var/log
2 ~
$ popd
$ pwd
/var/log
2024 © All rights reserved - buraxta.com