Skip to main content
Some useful Unix commands
- The most basic: navigation:
- cd, cd ..
- ls
- ls -alShr
- ls -alShr | less
- ls -alhF
- cp, mv, rm, rm -r
- The locations in which the shell searches for executables:
- Other useful echo commands:
- Finding stuff:
- find command
- Find all files with name "*alpha*" :
- find . -name "*alpha*" -print
- List of all such files in a text file
- find . -name "*alpha*" -print >> list.txt
- Number of such files:
- find . -name "*alpha*" -print | wc -l
- Find all txt files created in the last 60 days:
- find /home/you -iname "*.txt" -mtime -60 -print
- awk command
- sed command
- grep command
- locate command
- List only directories...
- find . -type d -depth 1
- ls -F | grep /
- ls -ld -- */
- Shell script: create many (in this example, 100) directories:
- for i in {1..100}; do mkdir subdirectory_$i; done
- mkdir subdirectory_{1..100}
- Add pdf extension to all files in a folder:
- for i in *; do mv $i ${i}.pdf ; done
- Finding the location of the executable which the shell runs when a command is entered:
- Current values of all environment variables:
- Counting
- the number of lines in a file
- creative use
- ls -alshr > tmp.txt wc -l
- find . -name '*.f90' | xargs wc -l
- redirect the output of a command into a file:
- command > filename
- Instead, if we wish to append in the file named filename:
- set > filename.txt;
- Content of a text file:
- head, tail
- cat,
- vi, nano, pico
- less
- Use of | and >
- Login as a root user:
- Getting help:
- man, man --help
- help
- whatis
- apropos
- info
- man 5 passwd
- man -a passwd
- Processes related information:
- System related info:
- System name
- Network host name:
- Kernel version
- Info about kernel release:
- machine hardware name:
- machine processor architecture name
- All of the above info together
- sysctl -n machdep.cpu.brand_string
- Hardware info:
- sysctl -a hw
- /usr/sbin/system_profiler SPHardwareDataType
- Storage related infor:
- /usr/sbin/system_profiler SPStorageDataTypesw_vers
- RAM:
- All CPU related info:
- Full info (this will take a lot of time and generate a lot of output, see help):
- /usr/sbin/system_profiler
- /usr/sbin/system_profiler -h
- /usr/sbin/system_profiler -listDataTypes
- Disk space
- diskutil list
- df -h
- du -h
Comments
Post a Comment