HOME

Linux tutorials

      HOW TO CREATE FILE IN LINUX

touch file file1 file2 file2
list the file
[root@localhost ~]# ll file
-rw-r--r--. 1 root root 0 Jul  4 13:01 file

To make directory
[root@localhost ~]# mkdir purchase

Add user
root@localhost ~]# useradd suresh
[root@localhost ~]# usermod  -c "admin" suresh
[root@localhost ~]# usermod -d /desktopusers/ suresh
[root@localhost ~]# ll /etc/passwd

alias
[root@localhost ~]# alias s='ls -l'
[root@localhost ~]# l
total 8
-rw-r--r--. 1 root root    0 Jul  4 12:55 03-07-2018
-rw-r--r--. 1 root root    0 Jul  4 12:48 accounts
-rw-------. 1 root root 1538 Jun 27 15:20 anaconda-ks.cfg

echo command
[root@localhost ~]# echo " this is test document " > file.txt
[root@localhost ~]# cat file
[root@localhost ~]# cat file.txt
this is test document
[root@localhost ~]# echo " new line is added to the file.txt document " >> file.txt   --- append the file
[root@localhost ~]# cat file.txt
this is test document
new line is added to the file.txt document

history command

[root@localhost ~]# history
1  poweroff
2  man -k files
3  man -k

vim essential commands
Esc  switches from input mode to command mode

i, a  current cursor position

o opens new line

:wq  writes the current file and quit

:q!  without applying changes and quit

dd   copies the line

yy  paste the current selection

p  pastes the current line

gg goes to the first line in the document

ctrl+r redoes the last undo

G  goes to the last line in the document

/text  searches the text and position the cursor
^ first position in the current line

:%s/old/new/g    replaces old word and enter new word

man
[root@localhost ~]# man -k group
endgrent (3)         - get group file entry
fanotify_init (2)    - create and initialize fanotify group

1     -  Executes programs or shell commands
5     -  File formats and conventions
8     -  System administration commands

 

File systems
/ root directory  and it is basic structure
/bin  executuable files are needed to repair a system in a minimal TS
/boot files are needed to boot linux kernel
/dev for accessing physical disks
/etc for maintaining configuration files
/home used for local home directories
/lib, /lib64 programs is used in /boot /bin /sbin
/media /mnt  mounting devices in a tree
/opt for optimal packages
/proc  this is file system to access kernel information
/root home directory for root user
/run contains run time environment
/sbin for system administrator commands
/srv  used the data by NFS, FTP AND HTTP
/sys used as an interface to different hardware devices that is managed by linux kernel and associated processes
/tmp contains temporary files
/var contains log files, mail boxes and spool files
df
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  3.1G   14G  19% /
devtmpfs                 897M     0  897M   0% /dev
[root@localhost ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G  3.1G   14G  19% /
[root@localhost ~]# cd  -----directly go to root
[root@localhost ~]# pwd   known path
/root

ls
ls -l   long listing
ls -d show name of directories
ls -R contents of current directory
ls -a shows all hidden files
cp
cp -R /etc/tmp copying all including sub directory
cp -a /documents  -- entire directory

mv
mv file1 /tmp
rm remove files
rm filename
head and tail commands

tail -5 /var/log/messages
head -5 /var/log/messages

cut
cut -f 3 -d : /etc/passwd
ps aux | tail -n 10

chvt -- switching terminals
chvt 3   -- console mode vty  ctl+alt+f6
chvt 1  -- graphical mode    ctl+alt+f1

w

[root@localhost dev]# w
root     :0       :0               10:57   ?xdm?   2:09   0.31s /usr/libexec/gnome-ses
root     pts/0    :0               12:00    5.00s  0.21s  0.06s w
root     tty3                      12:04    2:37   0.04s  0.04s -bash

systemctl reboot or reboot
systemctl halt or halt
systemctl poweroff or poweroff