Update some useful Unix commands when I have free extra time.
Mostly will be common or interesting commands.
chmod is used to change the permissions of files or directories.
chmod 777 /dir/subdir/file
755 – The owner has all the permissions to read, write and execute. Everyone else can only read and execute, but cannot make changes to the file.
777 – Everyone can read write and execute.
644 – Only the owner can read and write. Everyone else can only read. No one can execute the file.
655 – Only the owner can read and write, but not execute the file. Everyone else can read and execute, but cannot modify the file.
The chown command changes the owner and owning group of files.
Set the owner of file.rtf to mary
chown mary file.rtf
Recursively grant ownership of the directory /dir/subdir and all files and subdirectories to user mary
chown -R mary /dir/subdir
Sometimes we want to count files or directories number under a certian directory
Count files or directories number under current dir
ls -1 | wc -l
Recursively count files or dir number under the DIR_NAME dir
find DIR_NAME -type f | wc -l
Sometimes we want to know the total size of files under a certain directory
Count the size of the directory, human readable way(such as 100M).
du -sh DIR_NAME