Reminder of commands for Linux

In this post I will be putting some terminal commands that I use and it description

du

du -hs FOLDER_TO_CHECK

This command summarizes disk usage of each FILE, recursively for directories. Allows to check the size of a folder in the terminal.
-h Human Readable changes bytes for MB or GB
-s Summarizes

nmcli

nmcli device show eth0 [or your iface ]| grep IP4

Returns information about the network interface, like DNS, routes, domain

mc

This command doesn’t comes by default, but you can install it with apt-get and display some kind of file browser in the terminal.

htop

Kind of task manager in the terminal

find

find /some/dir -type d -exec chgrp www-data {} +
Very powerful and useful command to search files in from the terminal and allows to execute commands with the results also like in the example above, check the man file for more.

getfacl

Get current ACL’s for the given directory or file

setfacl

Set ACL permissions to a directory (using the -R option) or file
setfacl -R -m u:dnetix:rwx /var/www
setfacl -R -m g:www-data:rwx /var/www
setfacl -x g:www-data /var/www (Removes permissions)

wc

wc -l filename.some

Prints the line, word and byte count for a file or the text being piped to it, with the example command just displays the line count.

grep

grep --exclude-dir={dir1,dir2,*.dst} -rnw /path/to/somewhere/ -e "pattern"

Although there is nothing new about this command, too often I need to search for a file that has an specific text (pattern will be better) so this command will do exactly that, just replace the path and keep in mind that pattern it’s a regular expression not a text.

ssh

ssh -t user@example.com 'command1; command2'

Nothing new here, just want to remind how to send individual commands and then exit the connection

  • -t Allows user interaction, for example if command1 is vim or htop and you need to keep a connection while it last otherwise just ignore it

ssh-add

ssh-add -l

Manages private key identities to the authentication agent. Helpful options are:

  • -D Deletes all the cached keys used for the agent
  • -L Lists public keys
  • -l Lists private keys loaded by the agent

route

route

Displays all the routing that is configured for the actual networking settings and interfaces, pretty useful when using VPN connections

lsof

sudo lsof -wni tcp:80

Lists all the open files on your machine but in the example case outputs the command, PID and user that is using the port 80 in this case, really useful when you need to kill a process that is using a specific port

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s