Basic Linux Commands
Display details about commands
man command
List contents of a directory
ls
ls -l
alias ll='ls -alF'
alias la='ls -A'
alias ls="ls --color=auto"
Path
pwd
Go to home directory
cd
Move a level up
cd ..
Return to the previous directory
cd -
Go to a specific directory
cd /path/to/directory
Create
Create a new directory
mkdir /path/to/newdirectory/
Create a new subdirectory
mkdir -p /path/to/newdirectory/subdirectory
Copy
Copy a file
cp /path/to/file.xxx /path/to/destination/newfile.xxx
Copy a directory
cp -r /path/to/directory/ /path/to/newdirectory/
In Linux, folders end with a slash /
and files do not.
Move
Move a file to a new folder
mv /path/to/file.xxx /path/to/newdirectory/
Move a file to a new folder and rename it
mv /path/to/file.xxx /path/to/destination/newfile.xxx
Move a file to current directory
mv /path/to/file.xxx ./
Remove
Remove a file
rm /path/to/file.xxx
Remove an empty directory
rm -r /path/to/directory
Remove a directory and its contents
rm -rf /path/to/directory
Permissions
Change permissions for owner (u), group (g), and others (o), respectively, and (a) for all. You can call the above letters with operator (+, -, =) and permissions (r, w, x), which stand for read, write, and execute, respectively.
chmod ugo+r, o-wx /path/to/file.xxx
You can also use 3 numbers to set permissions. Each number is a sum of the following:
- 4 for read permission
- 2 for write permission
- 1 for execute permission
The first number is for the owner, the second for the group, and the third for others.
chmod 744 /path/to/file.xxx
Execute
Execute a file
./file.xxx
Multiple Shell Sessions
screen
Create a new session with a name
screen -S session_name
List all sessions
screen -ls
Attach to a session
screen -r session_name
Detach from a session
screen -d session_name
tmux
Create a new session
tmux
Create a new session with a name
tmux new -s session_name
List all sessions
tmux ls
Attach to a session
tmux a -t session_name
Detach from a session
tmux detach
Kill a session
tmux kill-session -t session_name
Rename a session
tmux rename-session -t old_session_name new_session_name