Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juanmaioli/46e7bf6ad406bfe35c2cf00a1ee7218f to your computer and use it in GitHub Desktop.
Save juanmaioli/46e7bf6ad406bfe35c2cf00a1ee7218f to your computer and use it in GitHub Desktop.
34 Comandos Útiles en linux, Tips y Hotkeys para la terminal

34 Comandos Utiles en linux, Tips y Hotkeys para la terminal

1) Copiar un archivo

Copiar readme.txt a el directorio documents

$ cp readme.txt documents/

2) Duplicar un archivo

$ cp readme.txt readme.bak.txt

Avanzado:

$ cp readme{,.bak}.txt

3) Copiar un directorio

$ cp -a myMusic myMedia/
# or
$ cp -a myMusic/ myMedia/myMusic/

4) Duplicar un directorio

$ cp -a myMusic/ myMedia/

5) Mover un archivo

$ mv readme.txt documents/

Siempre usar una barra final / cuando se mueven archivos

6) Renombrar un archivo

$ mv readme.txt README.md

7) Mover un directorio

$ mv myMedia myMusic/
# or
$ mv myMedia/ myMusic/myMedia

8) Renombrar un directorio

$ mv myMedia/ myMusic/

9) Sincronizar directorios

$ rsync -a /images/ /images2/	# note: may over-write files with the same name, so be careful!

10) Crear un nuevo archivo

$ touch 'new file'    # updates the file's access and modification timestamp if it already exists
# or
$ > 'new file'        # note: erases the content if it already exists

11) Crear un directorio

$ mkdir 'untitled folder'
# or
$ mkdir -p 'path/may/not/exist/untitled\ folder'

12) Show file/directory size

$ du -sh node_modules/

13) Ver propiedades de un archivo o directorio

$ stat readme.md      # on Linux

14) Abrir un archivo con el programa por defecto

$ xdg-open file   # on Linux
$ open file       # on MacOS

15) Zipear un directorio

$ zip -r archive_name.zip folder_to_compress

16) Unzip un directorio

$ unzip archive_name.zip

17) Listar el contenido de un archivo zip

$ zipinfo archive_name.zip
# or
$ unzip -l archive_name.zip

18) Borrar un archivo

$ rm my_useless_file

19) Borrar un directorio

$ rm -r my_useless_folder

20) Listar un directorio

$ ls my_folder        # Simple
$ ls -la my_folder    # -l: show in list format. -a: show all files, including hidden. -la combines those options.
$ ls -alrth my_folder # -r: reverse output. -t: sort by time (modified). -h: output human-readable sizes.

21) Vista Tree de un directorio y sus subdirectorios

$ tree                                                        # en Linux
$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'      # en MacOS o Linux
# Nota: se bebe instalar homebrew (https://brew.sh) para usar tree.
# brew install tree

22) Buscar una archivo

Por nombre

$ find . -iname "name"

Buscar un archivo modificado hace mas de 5 dias

$ find . -mtime +5

23) Calendario para terminal

$ cal

Mostrar un mes y año determinado

$ cal 11 2018

24) Calculadora para terminal

$ bc

25) Terminar un programa

$ killall program_name

26) Chequear la respuesta de un servidor

curl -i google.com

27) Ver ip Publica

curl ifconf.me

28) Ver ip's

ip a

29) Ver contenido de un archivo

$ cat readme.txt
# Si el archivo es muy grande se puede usar less para ver paginado.
$ less readme.txt

30) Buscar texto dentro de uno o mas archivos

$ grep -i "Query" file.txt

31) Ver espacio en disco

$ df -h

32) Ver performance del equipo

$ top

33) Ver procesos del equipo

$ ps -fax

34) Ver ultimas lineas de un archivo

$ tail /var/log/auth.log
$ tail -n 50 /var/log/auth.log #ver 50 lineas
$ tail -f /var/log/auth.log #ver ultimas lineas en tiempo real

Quick tips

$ !! #corre el ultimo comando
$ sudo !! #corre el ultimo comando como sudo
$ !<word> #corre el ultimo comando que incluya esa palabra
$ !<word>:p #lista el ultimo comando que incluya esa palabra
$ [espacio]<comando> #corre el comando para que no se incluya en el historial

Hotkeys

Ctrl + a  Go to the beginning of the line you are currently typing on
Ctrl + e  Go to the end of the line you are currently typing on
Ctrl + l  Clears the Screen, similar to the clear command
Ctrl + u  Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + h  Same as backspace
Ctrl + r  Lets you search through previously used commands
Ctrl + c  Kill whatever you are running
Ctrl + d  Exit the current shell
Ctrl + z  Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + w  Delete the word before the cursor
Ctrl + k  Clear the line after the cursor
Ctrl + t  Swap the last two characters before the cursor
Esc + t  Swap the last two words before the cursor
Alt + F   Move cursor forward one word on the current line
Alt + B   Move cursor backward one word on the current line
Tab       Auto-complete files and directory names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment