-
Notifications
You must be signed in to change notification settings - Fork 0
UNIX
Kyle Coberly edited this page Dec 28, 2020
·
3 revisions
-
mkdir- Make a directory (-pfor nested/file/structure) -
touch- Create a file -
cp- Copy (-rfor recursive,-ito prompt for overwrites) -
cmp- Compare files -
diff- See difference between files. (-ifor case-insentive,-Bfor ignore blanks,-wfor ignore whitespace)-
<- File 1 -
>- File 2 -
d- Delete -
a- Add -
c- Change
-
-
sdiff- Advanced diff. (-sto ignore matches)-
nothing- Identical -
<- File 1 -
>- File 2 -
|- Different
-
-
dircmp- Compare directories -
ls- List (-ato include hidden files,-lfor long form,-Rfor recursive) -
mv- Move or rename (-ifor interactive) -
rmdir- Remove directorys (can take multiple) -
find <directory> "<search string>"-
-print(display results) -
-exec compress {} \;(compress the file when you find it) -
-ok rm {} \;(delete the file when you find it)
-
-
mtime -4- (limit results to files modified in the last 4 days) -
locate <filename>- find system files -
ln <first file> <second file>- Hard link two files together. (-sfor soft link, plus dirs)- Hard links are identical, soft links are dependent
-
file <file_name>- Display file metadata -
split -b 500M big_file.jpg- Splits into 500MB chunks- Use cat to recombine
-
sort file_1 file_2 > destination_file- Sort by first character of each line-
-t, +1(comma delimited, sort on second field) -
-uto eliminate duplicates
-
-
uniq <file_name>- Removes duplicate lines -
tr a-zA-Z A-Za-z < <file_name>- Translate file -
fmt <file_name> -w 60- Format file to a 60 character line -
wc = word count--wfor words,-lfor lines,-cfor bytes). Can pipe fromls.
-
less- Paging (scroll up and down with arrow keys) -
more- Paging (spacebar, b [if no pipes], q to quit) -
|- Pipe output to input -
>- Redirect output to something other than screen -
>>- Append to output -
tee- Sends output to multiple locations- | tee <first_output> | <second_output>
-
chsh- Change shell -
tab- Autocomplete, twice for options- up, down to search
-
ctrl + a- Beginning of a line, ctrl + e = end of a line -
stty,stty sane,reset- Fix weird remote issues -
exit- Quit shell -
alias- Show a list of aliases -
alias <new>=<old>- Set a shortcut for the session only -
;- Separate commands on the same line -
&&- Same as;, but only runs if the first one succeeds -
history <number>- Show lines of history -
env- Print your environment variables -
<variable_name>=<value>- Sets a shell variable -
export <variable_name>- Makes a shell variable an environment variable -
export <variable_name>=<value>- Set an environment variable -
echo $<variable_name>- Show a variable -
alt+.- Pull up the final argument of the last command. Keep pressing for previous commands. Useful when you have to do several things to the same file. Requires this in vi-mode:bindkey "\e." insert-last-word.
-
$PS1- Regular prompt -
$PS2- Secondary prompt -
%n- Current user -
%~- Current directory with path -
%c- Current directory without path -
%t- Time -
%w- Date, no year -
%W- Date with year -
\n- Force new line -
%m- Hostname -
%M- Hostname with domain
-
cat- Display, can take multiple files, can redirect into another file -
tac- Reverse cat -
head/tail -20- File start or end of file. Can do multiple files. -
tail -f- "follow" updates -
grep <needle regex> <haystack>- search. (-5for context lines,-cfor count,-vfor all lines that don't match,-ifor case-insensitive) -
ctrl+r- Reverse search through history
-
sed 's/old/new/gim' <source_file> > <destination_file>- Search & replace- Can save
seds as scripts -
g= global,i= case-insensitive,m= multiline
- Can save
-
awk -F, /search/{ <command> $1 } <file_name>- Work with delimited files-
-Fsets delimiter,$1is the first field - Can save
awks as scripts
-
- What shells do you have available?
cat /etc/shells -
shhas no completion or aliasing -
cshallows you to script in C -
bash/ksh/zshallows a blend of features and simple scripting - Temporarily jump into a shell by executing it
-
zshautocompletion while cycle through options while tabbing
- Multiple commands can be separated with
;-
&&is the same as;, but only runs if the first one succeeds
-
- Find out what shell you’re using with echo $SHELL
-
*is a general wildcard,?is a single-character wildcard - History is in
~/.bash_history- good for stubbing out scripts -
^cd^lsruns last command, swapping outcdforls -
nano:pico::vim:vi - Find out what group you’re in with grep username /etc/passwd
- Find out general group info with
more /etc/group - A
tat the end of a permissions list is a "sticky bit", and means it can only be modified by its owner - You own any files that you
cp - Shell variables are tied to the shell, environment variables exist for any shell
-
zshconfig is in/etc/zprofile,/etc/zshenv,/etc/zsh/zshrc. - User overrides are in
~/.zprofile,~/.zshrc - Edit the
PATH=in.zshrcto add more default paths -
alias <new>=<old>- Set a shortcut. Goes in.zshrcfile.