Shell Basic Command File Management - wwangdev/wwangdev.github.io GitHub Wiki
#Shell Basic Command -- File Management
Need to know
-
Linux use '/' instead of '' to for directories.
-
Linux File System Hierarchy: "man hier" for more details
- /bin
- /boot
- /dev
- /etc
- /home
- /lib
- /lib64
- /mnt
- /opt
- /proc
- /root
- /sbin
- /tmp
- /usr
- /var
- /lost+found
-
Mode bits: owner(u), group(g), and others(o); each has three bits -- read(r), write(w), and execute(x).
-
For folders: x -- entrance, r -- list files, w -- rm/mv/touch files.
-
File Types:
- -: regular file
- d: directory
- b: block file
- c: character device file
- p: named pipe file or just a pipe file
- l: symbolic link file
- s: socket file
Share Files
Make group example
- $ sudo groupadd workgroup add a group named workgroup
- $ sudo useradd -G workgroup xxl add user xxl to workgroup
- $ sudo passwd xxl set password for xxl
- $ sudo mkdir work makedir with owner/group root
- $ sudo chgrp workgroup work change group of work to workgroup
- $ sudo chmod g+rwx work add group mod of work of rwx
- $ sudo chmod o-rwx work remove other mod of work of rwx
- $ sudo chown ww work change owner of work to ww
- $ touch test make a file
- $ su xxl switch to user: xxl
- $ rm test delete file test
If want to add an existing user to a group, use:
sudo usermod -a -G workgroup xxl: -a:append.
Directory and File Manipulation
New
- mkdir: make directory. -p: make parents directory if needed.
- touch: make empty file or modify the establish time and date of a file.
Move
- mv: move. -i: prompt when overwrite, -b: add "~" to old files when conflict.
- mv: rename.
Copy
- cp: copy. -i: prompt when overwrite, -b: add "~" to old files when conflict, -r: recursive, with folder.
Remove
- rmdir: remove a directory
- rm: remove file/directory. -i: prompt, -f: no prompt even with read-only file, -r: recursive.
Change owner and group
- chown: sudo chown xxl:workgroup work change work's owner to xxl and workgroup to workgroup.
- chown :nogroup keep owner and change group to nogroup
- chown -R: recursive.
- chgrp: chgrp XXX is the same as chown :XXX.
Change mode
- chmod: chmod [ugoa][+-=][rwx].
- chmod o=u XXX mod other as user mode bits
- Only owner and root can modify mode bits.
- chmod 751 XXX rwxr-x--x
Link
- ln: ln-s Target Link_name link a Link_name to Target
- ln -s: soft link; no "-s": hard link. Use -s!
Redirect
- >: write to.
- >>: append to.
- <<: << XX : read until XX.
Pipe
- |: ls | grep ay ls result as input of grep ay