Useful Unix Commands
Update some useful Unix commands when I have free extra time.
Mostly will be common or interesting commands.
chmod
chmod is used to change the permissions of files or directories.
example:
1 | 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.
chown
The chown command changes the owner and owning group of files.
example:
Set the owner of file.rtf to mary1
chown mary file.rtf
Recursively grant ownership of the directory /dir/subdir and all files and subdirectories to user mary1
chown -R mary /dir/subdir
Count files number under certain directory
Sometimes we want to count files or directories number under a certian directory
example:
Count files or directories number under current dir1
ls -1 | wc -l
Recursively count files or dir number under the DIR_NAME dir1
find DIR_NAME -type f | wc -l
Find out the directory size
Sometimes we want to know the total size of files under a certain directory
example:
Count the size of the directory, human readable way(such as 100M).1
du -sh DIR_NAME