In my current profession working as a system integration developer I mainly work with PHP as a server language.
Moreover, we work on Mac computers with Linux based file systems through terminals on a daily basis.
In this post, I have just listed a few handy Linux commands.
| Command: | Description: |
| chmod +rwx <file> | Add permissions to read, write and execute a file. |
| chmod -rwx <file> | Remove permissions to read, write and execute a file. |
| clear | Clear the console. |
| cp <file1> <file2> <destination> | Copy multiple files to a directory. |
| diff -y -W 70 <file1> <file2> --supress-common-lines |
Compare differences between two files. The "y" flag displays the differences side by side, while the "w" flag lets you choose the row width to avoid nestled rows. |
|
find . -type f -name "*.php" |
Find all files with the file extension "php" in the current directory. |
|
find . -name file.txt |
Find all files named "file.txt" in the current directory. |
|
grep <search_word> *.txt |
Search for a specific word in all files with a certain file extension (in this case "txt" files) and then list matching files. |
|
grep -rl "text here" <dir> |
Search for all files including "text here" in a given directory. |
|
gzip -k <file> |
Zipp a file, but keep the original file using the "k" flag. |
|
kill <pid> |
Terminate a specific system process by its PID. |
|
kill -9 <pid> |
Force termination of a system process/PID. |
|
less <file> |
Read a file's content without edit mode, including pagination etc. |
|
ls -a |
List all content such as files and directories in the current directory. |
|
lsof -i : <port> |
List all processes using a specific port. |
|
mkdir <folder> |
Create a new folder in the current directory. |
|
mv <file> <destination> |
Move a given file to a given destination specified as a path. |
|
mv <filename> <newfilename> |
Change the name of a given file by "moving" it to its new name. |
|
mv *.png ~/<dir> |
Move all files with the file extension "png" to a given directory. |
|
php -a |
Aktivera en php-editor direkt i terminalen. |
|
ping <host> |
Pinga a host and check its status, e.g. "ping google.com". |
|
ps |
List all running system processes. |
|
ps -a |
List all system processes, including the ones not running. |
|
ps -ax | grep <appname> |
Find a system process by its name or PID. |
| pwd | Output the full path of the current directory. |
| rm -R <dir> | Remove a given directory/folder and its content in the current directory. |
| rm -f <file1> <file2> *.pdf | Force removal of two given files, including all files with a certain file extension (in this example "png"). |
| scp <file> | Remotely copy a file, e.g. "scp fil.txt" |
| ssh | Remote connect to a server, e.g. "ssh <ipaddress>". |
| su -c <command> <another_user> | Run a command as another system user. |
| sudo <command> | Execute a command as a super user. This is useful for commands requiring admin privileges. |
| tail <file> | Output the last paragraph from a file, e.g. "tail log.txt". This command is useful while troubleshooting given that errors are logged in some sort of file. |
| touch <filename> | Create a file in the current directory. |
| uuidgen | awk '{print tolower($0)}' | Create and output a lower cased UUID string (version 4). |
| whoami | Output the currently logged in system user. |
| !! | Run the latest command. |