You are on page 1of 6

https://t.

me/cotdrlab
https://www.howtogeek.com/412055/37-important-linux-commands-you-should-know/

alias
The alias command lets you give your own name to a command or sequence of commands. You can
then type your short name, and the shell will execute the command or sequence of commands for
you.
alias cls=clear

Cuando el nombre tiene espacios


escape the space characters properly (in other words, add the \ character before each space)

Pipes
Pipes allow you to send the output of a command to another command. In the UNIX philosophy,
each program is a small utility that do one thing well. For example, the ls command lists the files in
the current directory and the grep command searches its input for a specified term.
Combine these with pipes (the | character) and you can search for a file in the current directory. The
following command searches for the word “word”:
ls | grep word

ls -l: te da mas detalles

grep
The grep utility searches for lines which contain a search pattern. When we looked at the alias
command, we used grep to search through the output of another program, ps . The grep
command can also search the contents of files. Here we’re searching for the word “train” in all text
files in the current directory.
grep train *.txt

imprime solo las lineas del output que tienen lo que estas buscando. If no FILE
is given, recursive searches examine the working directory, and nonrecursive
searches read standard input. By default, grep prints the matching lines.

rgrep -l STR muestra todos los archivos que contienen el string

Condicionales grep:
OR: egrep 'str1|str2' o grep -e str1 -e str2 o grep 'str1\|str2'
AND: grep str1 | grep str2 o grep -E 'str1.*str2|str2.*str1'
NOT: grep -v str1
NOT AND NOT: igual qu
Output Redirection
The > character redirects a command’s output to a file instead of another command. For example,
the following line runs the ls command to list the files in the current directory and, instead of
printing that list to the terminal, it prints the list to a file named “file1” in the current directory:
ls > file1

Command History
Bash remembers a history of the commands you type into it. You can use the up and down arrow
keys to scroll through commands you’ve recently used. The history command prints a list of these
commands, so you can pipe it to grep to search for commands you’ve used recently.
The ~ character – also known as the tilde – represents the current user’s home directory. So, instead
of typing cd /home/name to go to your home directory, you can type cd ~ instead. This also works
with relative paths – cd ~/Desktop would switch to the current user’s desktop.

Run a Command in the Background


Add the & operator to the end of the command to have Bash execute the program in the
background:

Conditional Execution
You can also have Bash run two commands, one after another. The second command will only
execute if the first command completed successfully. To do this, put both commands on the same
line, separated by a &&, or double ampersand.

cat
The cat command (short for “concatenate”) lists the contents of files to the terminal window. This
is faster than opening the file in an editor, and there’s no chance you can accidentally alter the file.
cat .bash_logout

chmod
The chmod command sets the file permissions flags on a file or folder. The flags define who can
read, write to or execute the file.
One way to use chmod is to provide the permissions you wish to give to the owner, group, and
others as a 3 digit number.  The leftmost digit represents the owner. The middle digit represents the
group. The rightmost digit represents the others.

0: No permission
• 1: Execute permission
• 2: Write permission
• 3: Write and execute permissions
• 4: Read permission
• 5: Read and execute permissions
• 6: Read and write permissions
• 7: Read, write and execute permissions

Type -a <nombre> te muestra todas las ubicaciones que tienen ejecutables


con ese nombre

regex/regexp: regultar expresion es el string que buscas en algo. Ej lo que


buscas cuando haces buscar y reemplazar

Argumentos

$1→prmer argumento recibido


$2→segundo argumento recibido
….

$@ → es un vector de todos los argumentos

contar palabras de los argumentos

for FILE1 in "$@"


do
wc $FILE1
done

wc: cuenta # de palabras, bytes, archivos

makereport -u jsmith -p notebooks -d 10-20-2011 -f pdf

Bash enables this functionality with the getopts function. For the above example, use getopts as
follows:
while getopts u:d:p:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DATE=${OPTARG};;
p) PRODUCT=${OPTARG};;
f) FORMAT=${OPTARG};;
esac
done
chown
The chown command allows you to change the owner and group owner of a file.

curl
The curl command is a tool to retrieve information and files from Uniform Resource Locators
(URLs) or internet addresses.
Si le mandas -o <nombre archivo> te lo descarga

Ver espacio de almacenamiento: df -h


-h es para que lo puedan ver humanos (eb Gb)

The echo command can show the value of environment variables, for example, the $USER,
$HOME, and $PATH environment variables. These hold the values of the name of the user, the
user’s home directory, and the path searched for matching commands when the user types
something on the command line.

exit
The exit command will close a terminal window, end the execution of a shell script, or log you out
of an SSH remote access session.

find
Use the find command to track down files that you know exist if you can’t remember where you
put them. You must tell find where to start searching from and what it is looking for. In this
example, the . matches the current folder and the -name option tells find to look for files with a
name that matches the search pattern.
You can use wildcards, where * represents any sequence of characters and ? represents any single
character. We’re using *ones* to match any file name containing the sequence “ones.” This would
match words like bones, stones, and lonesome.
find . -name *ones*
free
The free command gives you a summary of the memory usage with your computer. It does this
for both the main Random Access Memory (RAM) and swap memory. The -h (human) option is
used to provide human-friendly numbers and units. Without this option, the figures are presented in
bytes.

head
The head command gives you a listing of the first 10 lines of a file. If you want to see fewer or
more lines, use the -n (number) option

history
The history command lists the commands you have previously issued on the command line. You
can repeat any of the commands from your history by typing an exclamation point ! and the
number of the command from the history list.
!188

kill
The kill command allows you to terminate a process from the command line. You do this by
providing the process ID (PID) of the process to kill. Don’t kill processes willy-nilly. You need to
have a good reason to do so. In this example, we’ll pretend the shutter program has locked up.

To find the PID of shutter we’ll use our ps and grep trick from the section about the alias
command, above. We can search for the shutter process and obtain its PID as follows:
ps -e | grep shutter.

Once we have determined the PID—1692 in this case—we can kill it as follows:
kill 1692

less
The less command allows you to view files without opening an editor. It’s faster to use, and
there’s no chance of you inadvertently modifying the file. With less you can scroll forward and
backward through the file using the Up and Down Arrow keys, the PgUp and PgDn keys and the
Home and End keys. Press the Q key to quit from less.

You can also pipe the output from other commands into less.

apagar la pc: sudo shutdown now


Mirando el estado de tu HD:

* instalar el paquete smartmontools (en apt y pacman está)

* ejecutar sudo smartctl /dev/sda -HA


> mirar que "overall-health" esté en PASSED
> mirar que los attributos tengan VALUE alejado de THRESH (cuanto más chico es VALUE peor)
(WORST dice cuál es el VALUE más pequeño que se ha visto en el HD)
(si querés saber más de los attributos indagá sobre "smart attributes")

* ejecutá un test corto con sudo smartctl -t short /dev/sda y dps mirá los resultados en sudo smartctl
-l selftest /dev/sda (deberían tener status="Completed without error")

You might also like