Linux commands

¡Supera tus tareas y exámenes ahora con Quizwiz!

passwd

Modify a user password example: passwd cindy changing password for cindy (current) UNIX password: Enter new UNIX password: Retype new UNIX password: Passwd: Password successfully updated

scp

Secure Copy Protocol file transfer between computers example: scp /home/cindy/Desktop/myfile.txt cindy @104.122.131.215: output: [email protected]'s password: after entering password we can verify that the file successfully copied over

sigint

Terminal interrupt - user hits interrupt keys can send a sigint signal with Ctrl + C example: in the sudo parted shell you can use Ctrl + C and it will terminate the parted shell back to bash

man

manual pages (man pages) used to display the user manual of any command we can run on the terminal more detailed them --help example: man ls

dpkg

package manager for Debian

hide a file

prepending a dot to it example: .I_am_hidden

pwd

print working directory tells you where you are

sigTSTP

signal for terminal stop which will put your process in a suspended state example: kill -TSTP 10754 you can also use control Z

rm

remove file example: rm text1.txt

-l

shows file directory - makes directory more readable shows detailed information about files and folders in the format of a long list similar to windows, shows properties shows file directory size, modified date and time, file or folder name and owner of file and its permissions example: ls -l

-lh

shows files in human readable format example: ls -lh

uptime

shows info about current time, how long your systems running, how many users are logged on, what the load ave of your machine

Top

shows the top processes that are using the most resources on our machine also get a quick snapshot of total running or idle, cpu usage, memory usage and more

parted -l

shows what disks are connected to the computer example: sudo parted -l example to choose the USB drive we are going with sudo parted /dev/sdb you are now in the parted interactive This USB drive has an error "unrecognized disk label" to set disk label mklabel

mkfs

build a Linux filesystem example: quit to shell from parted mkfs -t ext4 /dev/sdb1; formats the partition

sigCONT

continues signal example: kill -CONT 1083

cp

copy file example: cp my_very_cool_file.txt ~/desktop to copy file to another directory to make a file of file cp my_very_cool_file.txt -T lemon makes a new file with the contents copied to lemon

history

history of all commands given in a program

to find file permissions

ls -l you can add a file name to look at the permissions of a specific file example: ls -l ~my_file output: -rwxre-r-- 1cindy cool-group Oct 9

You can run a file using group permissions or set group ID

ls -s /user/bin/wall -rwxr-sr-x 1root tty 27368 June 14 17:51 /user/bin/wall (tty is group ID) sudo chmod 2755 my_cool_folder (or sudo chmod g+s my_cool_folder) ls -l my_cool_file -rwxr-sr-x 1devan best_group_ever 0 Oct 9 17:49 my_cool_file

--help

view options available for a command example: ls --help

passwd -e

will immediately expire a users password and then make them set a new password the next time they log in example: sudo passwd -e victor password expire information changed

head

will show you by default the first 10 lines of a file example: heat fruits.txt

tail

will show you by default the last 10 lines of a file example: tail fruit.txt

grep

to find things inside file example: search single file grep cow farm-animals.txt example: search multiple files grep cow *_animals.txt

sudo blkid

to get UUID of device

We use the h parameter to tell us dnsmasq that we want to

to include this list in the information being served. (the exe host file list created) sudo dnsmasq -d -q -H myhosts. cat myhost.txt example output: 192.168.1.2 heluim.local 192.168.1.7 nitrogen.local 192.168.1.8 oxygen.local

apt update

to make sure you're getting the most up to date software in your repository won't install or upgrade packages for you example: sudo apt update

mount

to mount the disk or drive to a directory example: sudo mount /dev/sdb1 /mu_usb/ now if we go to my usb we can start reading and writing to the new file system

mkpart

to partition disk needs to have 1 type partition 2 what file system 3 start of disk and end of disk example: mkpart primary ext4 1Mib 5Gib the partition type is only needed in MBR so in GPT we just use 'primary' the start point is 1 mebibyte and end point of 5 gibibyte

/etc/fstab

to permanently mount a disk to automatically load up when computer boots example: cat /etc/fstab shows a list of unique ID's their mount points, type file system, etc.

cat

to read a file in bash example: cat important_document.txt

rm -r

to remove a directory and all of its contents example: rm -r misc_folder

mklabel

to set disk label example: mklabel gbt since we wnt to use the gbt partition table

umount

to unmount the file system example: sudo umount /my_usb or sudo umount /dev/sdb1

apt full-upgrade

to update kernel and other packages before running the apt full-upgrade command, remember to update your application sources with apt update example: sudo apt update now we can run upgrade sudo apt full-upgrade you can verify the latest kernel as being used with uname -r

etc/sudoers

to view the contents of a root restricted file example: cat /etc/sudoer Permission denied can only be read by a root user sudo super user do to access above file

~

used to return to your home directory example:cs ~/Desktop will take us back to our desktop

/var/log/syslog.file

logs proetty much everything on your system

ln

to create hard links example: ln important_file important_file_hardlink

ln -s

to create soft link example: ln -s important_file important_file_softlink

sudo userdelete

to delete user example: sudo userdelete Juan

to automatically mount swap space every time the computer boots up just add

/etc/fstab to swap entry

7z e

7 zip command to archive and unarchive folders extract files example: 7z e my_archive.tar check with ls to see extracted files

redirector operator

> will overwrite an existing file or create a new file >> will not overwrite a file example: echo woof >> dog.txt

Ctrl + R

A short cut to search through your command history You can bring up commands that you used previously and issue them over again

nslookup

A utility that is used to test and troubleshoot domain name servers. example: example: nslookup www.google.com example output: Non-authoritative answer:Name: w.google.comAddress: 216.58.194.164

lsof

Display a list of open files

sticky bit

It makes it so anyone can write to a file or folder but they can't actually delete anything only the owner of root can delete anything example: ls -ld/tmp (d flag is to look at the directory only - not the file) drwxrwxrwt 11rootroot 4096 Oct 10 10:58 /tmp the t in the user section means everyone can add and modify files in the /tmp directory, but only root or owner can delete

To uninstall a package we use the R or remove flag

example: sudo dpkg -r atom

/etc directory.

The directory that contains system-specific configuration files.

script session.log

This will write the contents of your session to the session.log file. When you want to stop recording, you can write exit or press Ctrl-D. The generated file will be in ANSI format which includes the colors that were displayed on screen. In order to read them, you can use commands like ansi2txt or ansi2html to convert it to plain text or HTML respectively.

sudo service vsftpd reload.

To reload a service after changes are made to the configuration without restarting and interrupting ongoing connections

Service NTP Status

We can check that there's an NTP daemon running on this machine

To install open SSH on client on a machine

What you're going to do is always, go to my client machine, and simply run this command, sudo apt-get install openssh-client It then is , downloading package

/var/log/auth.log

authorization and security related events

ping

a DOS command that tests connectivity and isolates hardware problems and any mismatched configurations example: You can do a quick check and ping a website that you know is available. ping www.google.com

apt to install a package

advance package tool package manager example: installing apt sudo apt install gimp parat of output is 0 upgrades, 18 newly installed, 0 to remove, and 16 not upgraded (this give us an overview of what we're doing to the package on our machine)

echo

alias of Write-Output example: echo woof>dog.txt

-a

all options This shows all files in the directory including the hidden files example: ls -a You can append two flags together ls -la is the same as ls -l-a

/etc/group

can view who has access to run sudo also view membership for all groups example: cat /etc/group output: 1st field is group name - sudo 2nd field is group password 3rd field is group ID 4th field is users in group

cd

change directory cd ~ or cd to return to the home directory cd/ to change to the root directory of linux file system cd/root/as root user - to go to root user directory cd .. to navigate up one directory cd - to go back to previous directories or folders

chgrp

change group command example: sudo chgrp best_group_ever my_cool_folder result: ls -l my_cool_folder -rwxr-xr-- 1devin best_group_ever 0 Oct 17:49 my_cool-folder

chrmod

change mode command to add or remove permissions use a plue or minus sign o = owner u = user g = group example: ls -l my_cool_file --w------- 1 cindy cool_group_0 Oct 9 17:49 my_cool_file (user, group, all) chmod u+x my_cool_file ls -l my_cool_file (to check) output: --wx------ 1cindy cool_group 0 Oct 9 17:49 my_cool_file

chown

change owner command allows you to change the owner of a file example: sudo chown deven my_cool_file result: ls -l my_cool_folder -rwxr-xr-- 1devin my_cool_folder 0 Oct 9 17:49 my_cool_folder

print

check the status of usb in above example in parted

If you want to add multiple permissions

chmod ugo+r my_cool_folder this says we want to grant read permission for the users, groups and owner a+w= all write to all a - can be used to add or remove permissions to all o,u, g

Standard error

displays error messages which you can get by using the two greater then (2>) redirector operator example: ls /dir/fake_dir 2> error_output.txt check by cat error_output.txt error message ls: cannot access '/dir/fake_dir' not such file or directory

uname

displays system information if you use -r with uname you see what kernel version you have

/var/log

directory - logs example: ls /var/log you will see many individual log files

df

disk free - to see how much free space you have in your machine example df -h

du

disk usage parameters -c print out as csv. Use -ct for tab delimiting -a specify sub directory depth of information (default is all levels -n do not recurse -v show size (in KB) of intermediate directions -u count each instance of a hard disk file -q quiet (not banner)

du -h

disk usage -h flag makes the data in human readable form example: du -h

less

does a similar thing that 'more' does in Windows, but has more functionality. We are launched into an interactive shell example: less large-document.txt up and down keys - page up and down g - moves you to beginning of file G - moves you to the end of a file. /word_search - allows you to search for a word or phrase Q - quit out and go back to your shell

removing permission

example --wx------ 1cindy cool_group 0 Oct 9 17:49 my_cool_folder change chmod u-x my_cool_group result: --w------- 1 cindy cool_group 0 Oct 9 17:49 my_cool_folder

Numerical permission lets us change all permissions at once

example instead of: chmod u+rwx my_cool_file chmod g+rw my_cool_file chmod o+r my_cool_file You can run instead: chmod 754 my_cool_file

< Standard in redirector operator

example: cat < file_input.txt

grep can be used to find a specific dpkg

example: dpkg -1 | grep atom the pipe command takes the standard output of one command then sends it to the input of the other command.

sigkill

example: kill -kill 10835 will terminate absolutely without giving time to clean up

Looking for error in log files

example: less /var/log/syslog |grep error

service status

example: service vsftpd status This tells us that the service is already running.

apt to remove a package

example: sudo apt remove gimp you can see it removers dependencies for us that we're not using anymore because we don't need gimp

To install a Debian package you need to use the D package or Debian package command

example: sudo dpkg -i atom-amd64.deb you need to use the i flag to install (atom-amd64.deb is the Debian package)

fsck

file system check example: sudo fsck /dev/sda don't run on a mounted file or you may damage it)

/etc/password

file the contains user information example: cat /etc/password a lot of information will be here. There are many processes running example of output: cindy@cindy-nyc: ~$cat /etc/password 1st field is username 2nd field is user password 3rd field is user id (UID)

dpkg -s

finds a package associated with specified files. example: dpkg -s /etc/host.conf if your not sure which package installed a file dpkg -s

To install open SSH server on a machine you want to access

go to the server and install the open SSH server. sudo apt-get install openssh-server.

apt --help

information about packages and more

sudo dpkg -i

install a package

To SSH into another machine, you need to

install an SSH client on the machine you're connecting from. Then install an SSH server on the machine you're connecting to.

apt upgrade

installs any outdated packages for you automatically to install any available update packages on your machine example: sudo apt upgrade

swap space, mk swap, linux-swap

is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space. Swap space can take the form of either a dedicated swap partition or a swap file. example: go into parted tool to set up partition sudo parted /dev/sdb/ mkpart primary linux-swap 5GiB 100% format the linux-swap file system on it End point of the drive says 100% which indicates we should use the rest of the of the free space on our drive to complete process we need to specify that we want to make swap space with the mk swap command quit out of parted sudo mkswap /dev/sdb2

/var/log/kern.log

kernel messages

nano

light weight text editor example: nano my_file Ctrl + G - opens help page Ctrl + X - saves work and/or exit nano

dpkg -L ufw

list all files installed by a package. In this case ufw package

dpkg -l

list debian packages that are installed on your computer

mkdir

make directory command allows the user to create directories or folders example: mkdir Lemon verify the file with ls

/dev/null file

metaphorical blackhole If we want to filter out the error messages in a file and just want to see standard out messages example: less /var/log/syslog 2> /dev/null not output is filtered from error messages

mv

move or rename files example: rename mv red_document.txt blue_document.txt example: move mv blue_document.txt ~/Desktop wildcard to move multiple files mv *_document.txt ~/Desktop

To change permissions numerically

numberical equivalence of rwx r = 4 w = 2 x = 1 the first number 7 is the owners permission the second number 5 is the group permission the third number 4 is the permission for all other users 7 = 4+2+1 = rwx 5 = 4+1 = rx 4 = 4 = r

Enabling setuid bit can be done

numerically - 4 symbolically - 5 example: sudo 4755 my_cool_folder check work ls -l my_cool_folder result: -rwsr-xr-x 1root deven best_group_ever 0 Oct 9 19:49 my_cool_folder (Owner shows setrid)

swapon

one more command to enable swap sudo swapon /dev/sdb2

parted

partitioning command line tool that supports both MBR and GPT partitioning

dig

query DNS servers and see their answers. example: dig www.example.com @localhost. The part after the @ sign indicates which DNS server we want to use (localhost) Our DNS server is telling us the IP address for the domain example.com.

sig

send a signal to a process

Bash tab

shows all options at once

Let's stop the dnsmasq service that's running, and then start it in debug mode.

sudo service dnsmasq stop (to stop dnsmasq) sudo dnsmasq -d -q (By passing d and q, we're telling dnsmasq that we want to run it in debug mode and that we wanted to log the queries that we execute.)

An alternative that's available in most services is the restart action, which does a stop followed by a start.

sudo service ntp restart date

If we want to reset NTP manually after a change what can you do?

sudo service ntp stop date sudo service ntp start date We use the stop action to stop the service and the start action to start it back up. Immediately after starting the service, we can see that the date and time are set back to the present.

Sudo

super user do run command with the security privileges of the super user example sudo cat /etc/sudoers you can now see the contents of this root user file

You can enable the sticky bit using numerical or symbolic format

symbolic = t numerical = 1 example: sudo chmod +t my_folder/ or sudo chmod 1755 my_folder/ ls -ld my_folder result: drwxr-xr-t 2cindy cindy 4096 Oct 5 16:14 my_folder/

/var/log/dmesg

system start up messges

checking logs in real time

tail -f /var/log/syslog tail -f the system log file and keep it on open window Ctrl +C to quit

pipe command

takes output of one command and use it as input of another command example: ls -la /etc | grep bluetooth The listing output from ls -la/etc goes to grep bluetooth to look for the word bluetooth in those files

Kill

terminate a process the kill command without any flags sends a terminate signal or sigterm this will kill the process but give it some time to clean up the resources it was using example: kill 10835 the kill command with the PID number

sudo useradd

to add a user example: useradd Juan you can combine this with password command to make user change password at log in

sudo date

to change the date of the machine example: sudo date -s "2017-01-01 00:00:00"

clear

to clean all the output from you screen

cp -r

to copy directory and all of its contents example: cp -r 'cat pictures' `/Desktop

dd

to copy files - a light weight tool that is used to clone a drive example of copy a usb drive 1. make sure drive is unmounted umount /dev/sdd 2. then run dd sudo dd if=/dev/sdd of =~/Desktop/my_usb_image.img bs=100M you should have an image of the usb drive on your desktop

wildcard asterick

to copy multiple files using a pattern example: cp *.png ~/Desktop

dpkg -l | grep apache2

this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed

Add a space to a file name

underscore = my_cool_file back slash = my\cool\file quotes = 'my cool file'

sudo dpkg -r

uninstall a package

ls

used for listing contents of a directory

setuid

we can enable files to be run by the permission of the owner of a file example: run a command to look at the permissions on a file ls -l/usr/bin/passwd result: -rwsr-xr-x rootroot 54256 May 16 19:37 /usr/bin/passwd the s stands for setuid when s is substituted where and irregular bit would be. It allows use of run the file with permissions of the owner of the file

to partition table GPT

we want to partition the USB /dev/sdb/ disk into two partitions


Conjuntos de estudio relacionados

Muscles of Facial Expression and Mastication

View Set

ELNEC Pallative Care Nursing Quizes. End of Life Nursing Education Consortium. Module 1: Introduction to Palliative Care Nursing. Section 2: An Overview of Palliative Care

View Set