

cd (change directory)
pwd (print working directory)
ls (list)
root account
root as / : the very first directory, refered as root directory
root home directory : /root
$ cd /var/log/samba
$ cd /var
$ cd log
$ cd samba
$ touch {name1} {name2} ...
: create empty file name1, name2, ...
$ cp {name1} {name2}
: copy file {name1} as {name2}
$ vi {name}
: bring you to file editor, shift + :wq! (write and quit)
$ mkdir {name1} {name2}
: make empty directory name1, name2,...
: cf. if you do not have permission, it can be denied
$ cp -R {name1} {name2}
: copy folder {name1} to {name2}

$ find {starting directory} -name "{finding name}"
$ locate {}

su - locate use a prebuilt database,find iterates over a filesystem to locate fileslocate is much faster than find, but can be inaccurate if the database is not updatedupdatedb
$ passwd {userid}


$ touch abcd{1..9}-xyz : create 9 files!$ rm a* : remove all the files starting with "a"$ rm *xyz : remove all the files ending with "xyz"$ ls -l ?bcd* $ ls -l *[cd]*

$ ln -s$ ln$ touch hulk
$ cd /tmp
$ ls -s /home/iafzal/hulk


$ touch hulk
$ echo "hulk is superhero" > hulk
$ cat hulk
$ cd /tmp
$ ln /home/iafzal/hulk

: there is no pointing in hardlink!

| hard link | soft link |
|---|---|
| 한 파일의 복사본을 만드는 것 cf. cp랑은 다른 개념! -cp는 원본과 복사본 파일의 inode가 다르다 -따라서, 복사본/원본의 수정여부가 서로에게 영향을 미치지 않음 | 바로가기 아이콘을 만드는 것 |
| 원본-하드링크 파일은 같은 inode를 가짐 | 원본-소프트링크 파일은 다른 inode를 가짐 |
| 어디에서 수정을 하던지, 함께 수정이 이루어짐 | 어디에서 수정을 하던지, 함께 수정이 이루어짐 |
| 원본을 지워도 하드링크 파일을 실행가능/내용보존 | 원본을 지우면 연결이 끊겨, 링크 파일 실행 불가능 |
| Type : "-" | Type : "l" |
출처 : 파일 링크 : ln - 하드 링크(Hard Link), 소프트 링크(Soft Link)
$ command option(s) argumnet(s)
ls : list files and directorys-l : list-t : order by time-r : reverse orderls -l {file or directory name} : list only the argumentrm : remove-f : forcefully-r : recursivelyrm -rf {file or directory name}mkdir : make directorymkdir {file or directory name}man {command} : manual for command
chmod : change modechmod g-w {file name} : remove write permissions from group in {file name}chmod a-r {file name} : remove read permissions from all in {file name}chmod u-w {file name} : remove write permissions from user in {file name}rm {file name} : cat {file name} : read filechmod u+rw {file name}chmod a-x {folder name}/


chmodchmod 777 {file name} 
chown : changes the ownership of a filechgrp : changes the group ownership of a file-R : recursive optionsu - : log in as rootexit : exit root
setfacl : set file ACL setfacl -m u:{user name}:rwx /path/to/file : change user's permissionssetfacl -m g:{group name}:rwx /path/to/file : change group's permissionssetfacl -Rm "entry" /path/to/dir : to allow all files or directories to ingerit ACL entries from the directory it is within setfacl -x u:{user name} /path/to/file : to remove a specific entry (for a specific user)setfacl -b /path/to/file : to remove a specific entry (for all users)
getfacl : get (current) file ACL$ whatis {command}$ {command} --help$ man {command}cf. MAC deos not support $ {command} --help any more!



$ echo "{text}" > {fileName} : override text!$ echo "{text}" >> {fileName} : keep lines and add line$ cat {fileName}3 redirects in Linux

Output

Input

Error


tee$ echo "{your text}" | tee {filename}$ echo "{your text}" | tee -a {filename}$ wc -c {filename}

$ ls -ltr | more$ ls -l | $ cp : copy
$ rm : remove
$ mv : move or rename
$ mkdir : make directory
$ rmdir or $ rm -r : remove directory
$ chgrp : change group
$ chown : chagne ownership (at the user level)
How to use?
$ cp {file1} {file2} : copy file1 to file2$ cp {file1} {directory} : copy file1 in directory (with the same file name)$ mv {file1} {file2} : change file name from file1 to file2$ mv {file1} {directory} : change location of file$ rm {filename} : remove file$ rm -Rf : forcefully remove the sub-directories and its contents as well$ chown {ownership} {file1} : change ownership of file1 to ownership (ownership - user, root)$ cat : views the entire content (regardless of 1 page, 2 page, ...)$ more : go over 1 page at a time$ less : go over 1 line at a time, in the reverse orderj : 1 line belowk : 1 line above (go back up)$ head : views top of the file$ head -{#lines} {filename}$ tail : views bottom of the file$ tail -{#lines} {filename}cut awkgrep and egrepsort uniq : uniquewc : word counts





$ diff {file1} {file2}$ diff {file1} {file2}tar : actually do not compress (nearly)tar cvf {file_name}.tar {directory} : taring files in {directory} to {file_name}.tar filetar xvf {file_name}.tar : untaring file {file_name}.targzip : compress filesgzip {file_name} : compress {file_name}gzip -d OR gunzip : compress / uncompress filesgzip -d {file_name} : uncompress {file_name}
truncate -s {size} {filen_name}
split -l {# of lines} {file_name} {splitted_file_name}
[Replace strings]
$ sed 's/{from_word}/{to_word}/g' {file_name}s : subtituteg : globally (multiple cases, at the same time)$ sed -i 's/{from_word}/{to_word}/g' {file_name}-i : insert[Remove strings]
$ sed 's/{from_word}//g' {file_name}$ sed -i 's/{from_word}//g' {file_name}[Remove all the lines containing strings]
$ sed '/{word}/d' {file_name}$ sed -i '/{word}/d' {file_name}[Remove empty lines]
$ sed '/^$/d' {file_name}^ : starts with$ : ends with[Remove 1st lines]
$ sed '1d' {file_name}[Replace tab to space]
$ sed 's/\t/ /g' {file_name}$ sed -i 's/\t/ /g' {file_name}[Print some lines only]
$ sed -n {starting_num},{ending_num}p {file_name}[Print file except some lines]
$ sed {starting_num},{ending_num}d {file_name}[Add empty line between lines]
$ sed G {file_name}[Replace strings except 8th lines]
$ sed '8!s/{from_word}/{to_word}/g' {file_name}
$ su - $ sudo -s : login sudo$ passwd root : change password for root[Add user]
$ useradd {user_name}$ id {user_name}$ cd /home and $ ls -ltr[Add groups]
$ groupadd {group_name}[Change group of user]
$ usermod -G {group_name} {user_name}
$ chgrp -R {group_name} {user_name}
$ cat /etc/passwd
$ cat /etc/group
$ cat /etc/shadow

[Add user with all options]
$ useradd -g {group_name} -s {shell_path} -c "{Description}" -m -d {home_directory} {user_name}
$ chage : change age, used to set parameters around password (cf. usermod)

$ whoami$ su - {user_name}$ exit$ su - : change user to root[sudo commands]
$ dmidecode$ fdisk -l$ usermod -aG wheel {user_name}







systemctl : system control
$ systemctl status firewalld.service$ systemctl stop firewalld.service$ systemctl status firewalld.service$ systemctl disable firewalld.service$ systemctl list-units$ systemctl list-units -all
ps : process status
top : show a real-time view of the running systemtop command


$ top -U {user name}$ sudo top press shift + s write kill as a signal write the PID that you want to kill

$ killall$ pkill

crontab gives vi editing mode!crontab - e : edit crontabcrontab -l : list crontabcrontab -r : remove crontab
$ ipconfig getifaddr en0 : local IP$ curl ifconfig.me : public IP$ bg$ fg$ nohup {process command}$ nohup {process command} > /dev/null 2>&1 &$ nice : e.g. $ nice -n 5 {process command}
$ top $ df : disk partition information$ df -h : more human readable$ sudo dmesg$ iostat : input output statistics$ iostat 1 : iostat with refreshing every 1 second$ netstat$ netstat -rnv$ netstat | more$ top -l 1 -s 0 | grep PhysMem | sed 's/, /\n /g'free command in Mac!$ sysctl -n machdep.cpu.brand_string$ cat /proc/cpuinfo in Mac!$ sysctl hw.ncpu : the number of CPUs$ sysctl hw.memsize
bootboot.log in /var/log$ log show --predicate "processID == 0" --debugcroncron directory in /var/log$ whereis syslog gives /usr/bin/syslog$ whereis cron gives /usr/sbin/cronsecure


