linux Flashcards
command to list out all the files or directories available in a directory
ls
This command lists the account name associated with the current login.
whoami
Sometime you might be interested to know who is logged in to the computer at the same time.
There are three commands available to get you this information, based on how much you wish to know about the other users:
users, who, w
command to get a count of the total number of lines, words, and characters contained in a file
wc
$ wc filename
2 19 103 filename
$
display content of a file and the line numbers
cat -n
cat -b (this will not count numbers of empty lines)
$ cat -b filename
1 This is unix file….I created it for the first time…..
2 I’m going to save this content in this file.
$
command to make a copy of a file
cp
$ cp source_file destination_file
command to change the name of a file
mv
$ mv old_file new_file
command to delete a file
rm
$ rm filename
formatted directory listing with hidden files
ls -al or ls -la
change to a directory
cd
show current directory
pwd
create a directory
mkdir
output the contents of a file as it grows
tail -f file
show kernal config
uname -a
show this months calendar
cal
show current date/time
date
show uptime
uptime
cpu info
cat /proc/cpuinfo
memory info
cat /proc/meminfo
show disk usage
df
show directory space usage
du
and du -sh for human readable version
show memory and swap usage
free
show possible locations of app
whereis app
search for a pattern in files
grep [pattern] files
grep -r pattern dir = search recursively for pattern in dir
command | grep pattern = search for the pattern in the output of the command
find all instances of file
locate
$locate file
halts current command
ctrl + c
stops current command
ctrl + z
brings most recent job to foreground
fg
lists stopped/bacgkround jobs, resume stopped job in the background
bg
log out of current session
ctrl + d
erases one word in current line
ctrl + w
erases whole line
ctrl + u
reverse lookup of previous commands
ctrl + r
list of commands used
history
repeat last command as root
!!
log out of current session
exit
brings job n to foreground
fg n
displays the details of the active user e.g. uid, gid, and groups
id
shows the last logins in the system
last
adds the group ‘admin’
groupadd “admin”
adds the user sam
adduser “sam”
delets user sam
userdel “sam”
forcefully removes a file
rm -f filename
removes a directory recursively
rm -r directory_name
encripts a file
gpg -c file_name
decrypts a file
gpg file_name.gpg
executes commands from standard input
xargs
lists files that are open by processes
lsof
find firefox process ID
pgrep firefox
visualizing processes in tree model
pstree
kills/terminates all processes named proc
killall proc
terminates process with a given pid
kill pid
displays all running processes
top
displays memory map of processes
pmap
searches for the id of the process “telnet”
ps aux | grep “telnet”
sts rwx for owner, rw for group and everyone
chmod 766
sets rwx to owner and r_x to group and everyone
chmod 755
sets rwx permissions to owner, group, and everyone (everyone else who has access to the server)
chmod 777
change owner and group owner of the file
chown owner-user: owner-group file_name
displays ip addresses and all the network interfaces
ip addr show
displays ip addresses of all network interfaces
ifconfig
retrieves DNS information about a domain
dig domain
performs refverse lookup on a domain
dig -x host
performs an ip lookup for the domain name
host google.com
displays local ip address
hostname -i
downloads a file from an online source
wget file_name
displays all active listening ports
netstat -pnltu
creates archive file called ‘home.tar’ from file ‘home’
tar -cf home.tar home
extract archive file ‘files.tar’
tar -xf files.tar
creates gzipped tar archive file from soruce folder
tar -zcvf home.tar.gz source-folder
compression a file with .gz extension
gzip file
install source (compliation)
./configure
make
make install
search for a given pattern in files
grep ‘pattern’ files
find file names that begin with ‘index’ in /home folder
find /home/ -name “index”
find files greater than 10000k in the home folder
find /home -size +1000k
securely connect to host as user
ssh user@host
securely connect to host using a specified pert
ssh -p port user@host
securely connect to the system via ssh default part 22
ssh host
connect to host via telnet default port 23
telnet host
securely copy file.txt to server2 in /tmp directory
scp file.txt server2/tmp
synchronize contents in /home/apps directory with /backup directory
rsync -a /home/apps /backup/
displays free space on mounted systems
df -h
displays free inodes on filesystems
df -i
shows disk partitions, sizes, and types
fdisk -l
displays disk usage in the current directory in a human-readable format
du -sh
displays target mount point for all filesystems
findmnt
mount a device
mount device-path mount-point
displays bootup messages
dmesg
displays information about systems hardware configureation
lshw
displays block devices related information
lsblk
displays pci devices in a tree-like diagram
lspci -tv
displays usb devices in a tree-like diagram
lsusb -tv
displays hardware information from the BIOS
dmidecode
displays information about disk data
hdparm -i /dev/xda
conducts a read speed test on device xda
hdparm -tT /dev/xda
tests for unreadable blocks on disk
badblocks -s /dev/xda
displays information about the user
finger username
query and change the system clock
timedatectl
shows system reboot history
last reboot