Jul 31, 2024
ls
Commandls
lists directory contents.-l
: Long listing format.ls -l
)
l
: Linkd
: Directory indicator-a
: Show hidden files.-t
: Sort by time modified.-h
: Human-readable sizes.ls -lath
to combine multiple flags.cd
Commandcd /etc
to change to the etc directorycd -
to go back to the previous directorycd ..
to go up one levelcd
to go to home directorypwd
Commandtouch
Commandtouch file1 file2 file3
mkdir
Commandmkdir dir1
to create a single directorymkdir -p parent/child
to create nested directoriesmkdir -m 777 dir
to set permissionscp
Commandcp file1 file2
to copy a filecp -r dir1 dir2
to copy directories recursivelyrm
Commandrm file1
to remove a filerm -r dir1
to remove a directory recursivelyrm file*
to remove files with a patternmv
Commandmv oldname newname
to renamemv file1 dir
to move a filedu
Commanddu -h
for human-readable formatdu -sh
for summarychmod
Commandchmod o-wx bad_dir
to remove write/execute for otherschmod g+x file1
to add execute for groupchmod 777 file1
for full permissionschown
Commandchown user file
to change ownerchown user:group file
to change owner and groupcat
Commandcat file1
to view contentcat file1 file2 > file3
to concatenatecat file1 >> file3
to appendtail
Commandtail file1
to view last 10 linestail -n 15 file1
for last 15 linestail -f file1
for continuous updateshead
Commandhead file1
for first 10 lineshead -n 15 file1
for first 15 linesless
and more
Commandsless file
or more file
less
using /
commandvi
, nano
i
to insert, esc
to exit insert mode, :wq
to save and quitctrl + x
to exit, y
to confirm saveps
Commandps aux
for detailed viewps aux | grep process_name
top
Commandtop
to starttop -u username
to filter by usertop -p PID
to monitor a specific processps
, sorted by memory usagekill PID
kill -9 PID
kill -2 PID
command &
jobs
fg %job_number
ping example.com &
fg %1
to bring to foregroundip
ip addr
ip route show default
ip route add subnet via gateway dev iface
ip addr add ip/mask dev iface
ss
ss -lt
for TCP, ss -lu
for UDPssh user@host
, ssh -p port user@host
scp file user@host:directory
rsync -options source destination
uname -a
for detailed infodf
df -h
for human-readable formatdf -Th
for file system typesfind /path -name pattern
find /path -size +1M
find /path -mtime -30
grep pattern file
grep -r pattern /path
tar czf archive.tar.gz files
to createtar xzf archive.tar.gz
to extracttar rf archive.tar file
to add filesgzip file
to compressgunzip file.gz
to decompressgzip -l file.gz
to list contentsuseradd username
-m
to create home directory-g group
to add to group-e YYYY-MM-DD
to set expiration dateuserdel username
-r
to remove home directorygroupadd groupname
, groupdel groupname