Linux 101 (NE classes, Udemy classes etc.) Flashcards
How to append the user to a secondary group?
usermod -aG [group] [username]
How to see all users and groups in the system?
/etc/passwd, /etc/group
How to give a group root privileges?
via adding the %groupname ALL=(ALL) ALL line to the /etc/sudoers file
Meaning: “any members of group groupname on ALL hosts can sudo to ALL user accounts to run ALL commands.
How to change ownership to a file/directory?
How change group ownership of a file with the other command?
chown [user].[group] [file]
or
chown [user]:[group] [file]
chgrp [group] [file]
How to change file/dir permissions? (2 methods)
Symbolically: chmod u=rwx,g+rw etc..
Numerically: chmod 753
How to locate a path to a given command?
which [command]
How to search the manual for keywords
man -k [keyword]
How does umask work?
By substracting numerically the permissions from any given file, od dir. So if umask is 777, the new directory will have 000 permissions. For files umask substract from 666 instead of 777 as it is for directories.
How to move, copy , rename directories (that have something inside of them)?
mv [dir] [destination]
cp -r [dir] [destination]
mv [old_name_dir] [new_name_dir]
How to put a directory into tar file with compressing?
tar -czf [new .tar file name] [directory]
How to compress, and uncompress files using gzip?
gzip [filename]
gunzip [filename]
How to view contents of .gz files? How to view content of tar files? (In human readable format, no cat command)
zcat [file]
tar -tf [file]
How to find a file (that is in your working directory) that starts with a “b”, then has two random letters, fourth letter is either “g” or “f”, fifth is a number from 1 to 6, sixth is neither “g” or “f”, and it ends with .txt?
ll -d (or ll | grep…) b??[g,f][1-6][!g,f]*.txt
How to redirect output of a text file to some other file replace it’s contents, and not show error message in a single command?
cat [file1] [file that doesn’t exis]> > [file2] 2> /dev/null
How to redirect output of a text file to some other file with replacing it’s contents, and not show error message in a single command?
cat [file1] [file that doesn’t exist ] > [file2] 2> /dev/null
How to redirect output of a text file to some other file and append it to it’s contents, and redirect error message to that same file? In a single command
cat [file1] [file that doesn’t exist]»_space; [file2] 2>&1
How to compare files in two ways?
diff [file1] [file2]
sdiff [file1] [file2]
How to display filetype?
file [file]
How to cat with number of lines displayed?
cat -n
How to display content of a binary file in a human readable form?
strings [file]
How to cut a selected portions of a file? Let’s say we want to print only name of a user, and his login bash from the /etc/passwd file.
grep [username] /etc/passwd | cut -d: -f1,7
How to customize shell prompt, and make the shell customization saved between sessions?
The shell customization information is storen in the PS1 env variable, and it content of that env could look like this: [ \t \u@\h \W]$
Most likely we want the customization options to be saved in between sessions, so we would have to put this line into the /~/.bash_profile:
export PS1=”[customization options]”.
This would load up those PS1 options everytime we login into interactive shell.
How to create an alias?
alias [aliasname]=[value]
How to make alias persist between sessions?
either put your alias into the /~/.bash_profile or /~/.bashrc file.