Thursday, January 17, 2019

Some useful Linux commands

Copy files from one folder to another

The below will command will copy all files inside the source folder to the destination folder.

cp path/to/source/* path/to/destination

This will not copy sub-folders and files in it.


cp -r path/to/source/* path/to/destination

or

cp -a path/to/source/* path/to/destination

This will recursively copy folders, sub-folders, and files in it.

Rename a folder


MV path/to/old path/to/new

Change read/write/access/owner/group permissions of a folder


CHMOD [XYZ] path/to/folder

X - Will affect Owner permissions
Y - Will affect Group permissions
Z - Will affect Others permissions

[X, Y & Z] will be calculated from below

0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute

For example, if we want to give Read, write and execute permission to Owner, Read & Execute permissions to Group and read permission to Others, we have to execute the command like below

CHMOD 754 path/to/folder

Change ownership of a folder or file with current user


sudo chown -R $USER /path/to/folder

No comments:

Post a Comment