Useful command to manage Ubuntu VPS

Useful command to manage Ubuntu VPS

Posted: 9 years ago in  Unix |


These commands are useful to whoever manage own VPS for the first time and in this article, commands are in Ubuntu system.


Connect to VPS

ssh username@domain_name_or_IP

List folder content

ls /path/to/folder

Copy file using same filename:

cp /path/to/source/file /path/to/destination/folder

Copy file using new filename:

cp /path/to/source/file /path/to/destination/file

Copy folder with same name:

cp /path/to/source/folder /path/to/destination/folder -R

Copy folder with new name:

cp /path/to/source/folder /path/to/destination/newfolder -R

Remove folder

rm /path/to/folder -R

Remove file

rm /path/to/file

Create folder

mkdir /path/to/new/folder

View a file

cat /path/to/file

View 10 first lines of file

head /path/to/file

View 10 last lines of file

tail /path/to/file

Search file

find /path/to/folder -name "filename.ext"

or using wildcard

find /path/to/folder -name "*.jpg"

Search string in file (-r force it to search recursively)

grep -r "search_string" /path/to/folder

We can use both find and grep in one line of command to limit which files that grep search

find . -name "*.php" | xargs grep "search_string"

Rename file: path should be the same with new filename

mv /path/to/file /path/to/new_file

File compressing

tar -zcf filename.tar.gz /path/to/file/or/folder

File decompressing

tar -zxf filename.tar.gz /path/to/file/or/folder