Linux command line tips

cd -: Go to the directory that you were previously in. You can use this when you want to toggle between two different directories.

We call anything that doesn’t take a value flag (ls -a). and anything that does take a value option.

Compress a file (abc).

tar czf abc.tar.gz abc

Uncompress a file. Note that you don’t need to use the z option.

tar xf abc.tar.gz

!!: Re-execute the previous command. It will be useful if you forgot to type cd and just typed paht/to/directory, you can run cd !! to execute cd /path/to/directory. Another example is to run sudo !! if you forgot to include sudo in the previous command.

touch foo{,1,2,3} equals to touch foo foo1 foo2 foo3.

find . -name src -type d: Search directories named src under the current directory. You can search python files by running find . -path '**/test/*.py' -type f. You can also search files and delete them by running find . -name "*.tmp" -exec rm {} \;.

du -sh [file name]: Display the file size of the specified file.

macOS only?
sysctl -n hw.physicalcpu_max: Display the number of physical CPU cores
sysctl -n hw.logicalcpu_max: Display the number of physical CPU cores
sysctl hw.memsize: Display memory size

You can check options for a shell script by running sh -x https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh.

Comments

Copied title and URL