Unix —useful commands
fallocate
- Preallocate size to a file.
% fallocate -l 15G temp_file
apropos keyword
- match commands with keyword in their man pages
% apropos copy
git-checkout-index(1) - Copy files from the index to the working tree
asn1_copy_node(3) - API function
git-checkout-index(1) - Copy files from the index to the working tree
gnutls_hash_copy(3) - API function
gnutls_hmac_copy(3) - API function
gnutls_pkcs11_copy_attached_extension(3) - API function
gnutls_pkcs11_copy_pubkey(3) - API function
gnutls_pkcs11_copy_secret_key(3) - API function
gnutls_pkcs11_copy_x509_crt(3) - API function
gnutls_pkcs11_copy_x509_crt2(3) - API function
gnutls_pkcs11_copy_x509_privkey(3) - API function
gnutls_pkcs11_copy_x509_privkey2(3) - API function
kubectl-cp(1), kubectl cp(1) - Copy files and directories to and from containers
asr(8) - Apple Software Restore; copy volumes (e.g. from disk images)
copy(9), copyin(9), copyinstr(9), copyout(9), copystr(9) - kernel copy functions
copyops(n), transfer::copy(n) - Data transfer foundation
cp(1) - copy files
cpio(1) - copy files to and from archives
dd(1) - convert and copy a file
ditto(1) - copy directory hierarchies, create and extract archives
dtfetchsymbolsd(1) - DT Remote service for copying symbol cache files from device to host
fcopy(ntcl) - Copy data from one channel to another
pax(1) - read and write file archives and copy directory hierarchies
pbcopy(1), pbpaste(1) - provide copying and pasting to the pasteboard (the Clipboard) from command line
scp(1) - OpenSSH secure file copy
ssh-copy-id(1) - use locally available keys to authorise logins on a remote machine
text(ntcl), tk_textCopy(ntcl), tk_textCut(ntcl), tk_textPaste(ntcl) - Create and manipulate text widgets
tqueue(n), transfer::copy::queue(n) - Queued transfers
uucp(1) - Unix to Unix copy
grep -flag keyword file
- Search the keyword in the file. We will only discuss flag n & c.
- when flag -n is used, grep prints the line numbers containing the keyword in the file.
- when flag -c is used, grep prints the no of lines containing the matching keyword in the file.
% grep -in test get-pip.py
175: # Execute the included pip and use it to install the latest pip and
2342:Rn-Hs#@-}oa4T{cf8d#cik*9Ew?)S4K}(teStynD$?zSSDhY@97wV-)Jlc2m58#p=8q*q7yzNuxW&aW
16286:SH{ep-!3&@oE}ZaVNl4rlJ<%{F*N(L1HkFp0XZ_`e#testbwIsj&?a)K^iIP!n<ueJU>Qvv{E$$;eVR
% grep -ic test get-pip.py
3
zcat
- zcat will read gzipped files without needing to uncompress them first.
% zcat get-pip.py.gz
% zcat get-pip.py.gz | less
file
- classifies the named files according to the type of data they contain.
% file *
Applications: directory
Desktop: directory
Documents: directory
Downloads: directory
Library: directory
Movies: directory
Music: directory
Pictures: directory
Public: directory
VirtualBox VMs: directory
a-cert: Netscape cookie text, ASCII text
cert.crt: PEM certificate
cert.pem: PEM certificate
csr.pem: PEM certificate request
get-pip.py.gz: gzip compressed data, was "get-pip.py", last modified: Fri Jun 10 08:47:38 2022, from Unix, original size modulo 2^32 1908226
du
- prints the size taken by each subdirectory or file in current directory.
% du -sh *
88K Amit
0B Applications
4.9G Desktop
dmesg
dmesg (driver message) command is used to examine the kernel ring buffer and print the message buffer of kernel. The output of this command contains the messages produced by the device drivers.
When the computer boots up, there are lot of messages(log) generated during the system start-up. You can read all these messages by using dmesg command. The contents of kernel ring buffer are also stored in /var/log/dmesg file.
systemctl isolate <target>
Use to command to change the run levels of the system using systemd.
- to reboot the system
% systemctl isolate reboot.target
or
reboot
or
shutdown -r now
- to poweroff the system
% systemctl isolate poweroff.target
or
poweroff
logger
This command is used to generate logs and process them against the syslog server ie: syslogd or rsyslog. After processing, logs are added to the respective log file based on syslog server configuration.
This is useful when there is a change in syslog server configuration and we need to test it manually.
% logger -p mail.err -t "test log" "test"
% tail -1 /val/log/mail.log
******** test test log: test
Process and jobs commands
- ps — to list the running processes.
- kill — to kill jobs and processes.
- crontab — to read, update, delete and create a cron entry.
- fg — to move a process to the front.
- bg — to move a process in the background.
- jobs — to list all the background processes.
Package Managers
- RPM based ie: RHEL, CentOS, Rocky, AlmaLinux, Oracle Linux
— yum (till RHEL 7.0), dnf (Starting with RHEL 8.0), rpm (low level — dependencies will not be installed).
- Debian based ie: Debian, Ubuntu, Kali Linux, Linux Mint
— apt (includes everything like apt-get or apt-cache), dpkg (low level — dependencies will not be installed).
System Configuration Information
- sudo dmidecode — To see the details about various machine configuration like cpu, memory, disk.
- nproc — To verify the number of processors.
- lscpu — To verify the list of CPUs running.