-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunix_notes.txt
145 lines (128 loc) · 9.19 KB
/
unix_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
!$ last argument in the previous history command
----- git -----
git commit -a commit with file deletions
git push push changes to remote repo
--------------------- viewing -------------------------
less +G filename displays the file in less, starting at bottom. when using less use G to go to the bottom (same as vim)
tac reverse of cat
--------------------- vi -------------------------
v vim visual mode, can select multiple line
:set paste vi paste mode on, prevents indenting issues
:set nopaste vim paste mode off
3dd vim delete three lines starting with current, put in buffer
3yy vim copy three lines starting with current, put in buffer
--------------------- tmux -------------------------
tmux action stroke is <ctrl-b>, will abbreviate as cb
tmux new -A -s andy create or attach to session named andy
cb, d tmux, to detach
cb, " tmux, split into horiz panes
cb, % tmux, split into vert panes
cb, arrow up or down tmux, move between panes
--------------------- find -------------------------
find * | grep searchstring finding a file or directory in any subdirectories from current location
find * | grep smpm.*cst this is how to use wildcards. Also: find * | 'grep smpm.*cst'
fd {filename} . finding a file in any subdirectories from current location. Can use {path} instead of .
find . -type f -name '*.m' -exec ls -l \{\} \; find all .m files in an subdirectories (the -exec part gives more details information)
find . -name '*.m' | xargs grep xxx look for the string "xxx" in all .m files in the current directory structure (recursive)
find . -name '*.dds' -exec grep xxx /dev/null \{\} \;
find {path} -type f -mtime -1 find all files modified within the last day. You can use . for the local directory instead of {path}
find {path} -type f -newermt 2017-02-01 find all files modified since this date. You can use . for the local directory instead of {path}
fd . {path} --changed-within 1d find all files modified within the last day. You can leave out {path} for local directory
find . -name '*.dds' -exec grep what /dev/null \{\} \;
find . -not -name '*.xlsx' -not -name '*.xls' find all files without these suffixes
-path '/home/khan/work/misc' -prune ignore these items
find ~ -type d -exec chmod 755 \{\} \; change all of my directories to this permission
find ~ -type f -exec chmod 644 \{\} \; change all of my files to this permission
find . -type f -maxdepth 1 | fgrep -v makefile | xargs rm find and remove all files except for those containing makefile in the name
find . -type f -name '*.m3d' -delete find and delete all files ending with this (handles files with spaces)
find . -type d find all directories
find . -type d | perl -pi -e 's/\//\\\\/g' | perl -pi -e 's/\n$/\\\\*.m\n/' *.m& find it at the end of the name
find . -name '*.m' -exec ls -l --full-time {} \; | awk '{$1=$2=$3=$4=$5=$7=$8="";sub(" ","")}1' | awk '{gsub(/-/,"",$1);print}' | sort find files with this suffix in the directory structure and sort by modify date
find . -type f -exec ls -l --time-style=full-iso {} \; | awk '{print $6,$NF}' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20120201 && $1<= 20120229 {print $1, $2}' | sort find between these times
find /mnt/u/work/calc_sheets -type f -exec ls -l --full-time {} \; | awk '{$1=$2=$3=$4=$5=$7=$8="";sub(" ","")}1' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20170201 && $1<= 20220229 {print $1, $2}' | sort find between these times
find . -type f -newermt 2017-02-01 ! -newermt 2022-02-29 | awk '{$1=$2=$3=$4=$5=$7=$8="";sub(" ","")}1' | sort find between these times
find . -type f -mtime -33 -a -mtime +21 -printf "%t\t%p\n" find file modified between 21 and 33 days ago
locate -d ~/.u.db "$PWD*/*.m" use locate to find all .m files from current location
updatedb -l 0 -o ~/.u.db -U /mnt/u update the locate database named .u.db with the contents of /mnt/u
locate -d ~/.u.db "$PWD*/*.m" | xargs -d "\n" ls -l use locate and give detailed information, need to use xargs -d "\n" to handle files with spaces
awk '{print $1}' print the first item in a space-delimited string, with newline
awk '{print $1,$2}' print the first and second item in a space-delimited string, with newline
awk '{printf "%s", $1}' print the first item in a space-delimited string, without newline
--------------------- grep -------------------------
grep 'term' filename look for 'term' in a single file
grep '^term' filename look for 'term' at beginning of a line
grep -nr {string} * look recursively in files and list name/line of occurence (but not files in current directory)
grep -nr {string} . look recursively in files and list name/line of occurence (including files in current directory)
grep -r --include '*.m' xxx . look for the string "xxx" in all .m files in the current directory structure (recursive)
grep -r --exclude '*.m' xxx . look for the string "xxx" in all files except .m files (recursive)
grep -v 'ADS\|hpeesof\|Found\|winfiles\|spanish\|Searching' * searching for things that don't contain these items
rm `ll | grep 2000 | cut -c 57-` remove all files created in 2000
grep -n '\.m$' * using \ for escape, must use ' ' around the expression
--------------------- copy all filetypes in a directory -------------------------
cd /home/khan;find . \( -path ./.snapshot -o -path */inside \) -prune -o -name '*.m' -exec cp -pax --parents \{\} /home/khan/misc/transfer_out/inside/mat/ \; find all .m files and copy with directory structure
cd /home/khan;find . \( -path ./.snapshot -o -path */inside \) -prune -o -name '*.xls*' -exec cp -pax --parents \{\} /home/khan/misc/transfer_out/inside/excel/ \; find all .xls files and copy with directory structure
cd /home/khan;find . \( -path ./.snapshot -o -path */inside \) -prune -o -name '*.py' -exec cp -pax --parents \{\} /home/khan/misc/transfer_out/inside/py/ \; find all .py files and copy with directory structure
--------------------- getting info -------------------------
touch -c -t 202303162046 filename change modification date to March 16, 2023. time = 20:46
date +"%F"
pstree -apl check process trees
pstree -apl `pidof cron` check things that are running as cron
du -h -d 1 current directory sizes in human readable format
ps -elf to show processes
kill -15 {pid} to kill a process with a chance for it to cleanup firce
kill -9 {pid} to kill a process forcefully
df -h checking disk capacity,usage, mount point
cat /proc/meminfo
cat /proc/cpuinfo
uname -a os info about the workstation
nmap -sP anand/24 find computers on the same subnet as anand
nmap -sP 173.23.140.1-255 check for all computers on this subnet
nmap -p 22 anand/24 scan for port 22 on this subnet
mtr google.com better than traceroute
lft google.com better than traceroute
ifconfig eth0 169.254.185.150
sort {filename} sorts the file alphabetically
uniq {filename} displays the unique lines of the file
python3 -m http.server shares the current directory (on remote browser using http://ip:8080)
pushd /mnt/u/work; python3 -m http.server 8080; popd
source !$ source the file that you just edited with the last command, !$ takes the last argument of the previous command
ls -al *.mat | cut -c 57- > files.txt save a listing of all .mat files into a text file
od -x -N10 {filename} listing first 10 bytes of a binary file (octal dump)
xxd -l 100 -c 12 -p {filename} listing a binary file, without line numbers, first 100 bytes, 12 bytes per line
xxd -l 100 -c 32 {filename) show the ASCII equivalent
env | sort > out.txt 2>&1 dump results, have STDERR and STDOUT go to file
sed -i 's/ugly/beautiful/g' a.txt replace all occurances in the file
chsh -s /bin/bash change default shell
ypchsh change default shell
echo "somestring1234" | cut -c 3- remove 2 characters from the beginning
echo "somestring1234" | rev | cut -c 3- | rev remove 2 characters from the end
yppasswd khan change password
man ls | col -b > out.txt piping the man command to a text file
ypcat hosts | grep msoe to find the ip address
stty erase <backspace><cr> ftp backspace fix
tar -cvf {filename.tar} {dir} to create tar file
tar xf {filename.tar} to unpack
tar xvfz {filename.tar.Z} to uncompress and unpack
tar -zxf {filename.tar.gz} to unpack
tar -jxf {filename.tar.bz2} to unpack
bunzip2 {file.bz2} unzip
time cp {filename} how long to execute the copy command
chase {filename} to change the file name to all lower case
chase */*/* to change all filenames in current & sub-directories
dos {filename} remove <cr> if present, adds <cr> if not present
diff compare two files, terminal mode
rsync -a --delete --exclude='*.ds' matlab /scratch archive the matlab directory into /scratch directory (deleting things in the archive that have been deleted in the original)
declare -F show all function names declared in the shell
declare -f show all function contents declared in the shell
declare -f function1 show function contents for function1
-------- Bash Tips -------------
ctrl-r search through history
ctrl-w erase word
ctrl-u erase from here to beginning of the line
ctrl-a move the cursor to the beginning of the line
ctrl-e move the curor to the end of the line
-------- Putty pscp -------------
cd c:\Files\Plink
pscp [email protected]:/usr/loca/local/bin/* u:\work\
vncserver :67 -geometry 1280x965
vncserver -kill :67