This page lists the most common usage commands while operating a linux.
How to empty a file
To empty a file, text, log or any other, of its content, while keeping the file there, we can either open the file and remove all the content in it, or we can use a simple command:
>filename
Simply write “>” and then write the file name. Make sure you’re in the directory where this file is located.
Can this work by giving path to the file? (not confirmed by me, check and update).
List all files with details
Listing all files takes “ls” while for listing all files with details including file permissions, owners detail, file size and last modified date, use this command:
ls -l
This will simply list all the files in selected or current directory.
SSH to server with custom port
To ssh to a server, use this command:
ssh -p 22 user@domain_or_ip
You can skip the “-p 22” part if the port is default, that’s 22. (-p means port and 22 means the port number).
However, make sure you keep the same sequence, you can’t add the port after the user and domain part.
How to delete a file
Delete or remove a file by simply using this command:
rm filename
The “rm” command followed by file-name that we need to be deleted.
How to rename a file on terminal
Renaming a file on terminal, on linux or mac os x, can be confusing for some people, however it’s pretty simple.
You simply have to use the command for moving the files, like this:
mv initial-file-name destination-file-name
The command will rename the file, in the same directory, not necessarily moving it to any other folder.
How to search files above specific size in linux
You can search for the larger files, above specific file size, using this command:
find /directory/path/ -size +20M
This command will find files in our specified folder, that are 20MB or above. (MB or Mb?, I guess MB, confirm and update)
How to zip a file on ubuntu terminal
On ubuntu or any other linux or mac os x, with zip installed (if not, then: apt-get install zip), use this command to zip all the files in a folder:
zip -r newzipname.zip foldertozip/
-r will zip all the files in it recursively.
How to CHMOD permissions recursively
Simply follow this:
chmod -R 755 folder/path/
This will set this permission for this folder and all files and folders inside it too.
Check:
Which version of centos installed: cat /etc/issue
If nginx installed: nginx -v
If memcached installed: php -m | grep memcache
For all php modules: php -m