LINUX commands

1)To list all files

2)To list files with file size
ls -lh

3) list files, including the hidden and files with (.) dot extensions
ls -larth

4)To go to the end of file
tail -f /root/

5i)To edit/create a crontab
crontab -e

5ii)If the cron job is in different directory add the following in the shell script which

the cron calls

6)To go to the top/end of a long file, type the following while the file is open

7)To change read/write/execute permission of the file

8)To call website from linux OS

9)In shell scripts there should be no spaces between variables and = sign

10)To replace a word, go to the beginning of the word and type

11)To delete a line, press


12) If you have the vim editor installed, can try out the following
dd --> to delete a line
yy --> to copy a line
p --> to paste the above
Shift6 --> to go to the beginning of a line
$      --> to go to the end of file

13) To find details of a definite process running:

ps -ef | grep
For eg, ps -ef | grep mongod 

14) Recursively find a string from a location
grep -r  "string"
For eg. grep -r "doel" /home/ets/passwd

15)Copying Files:
Copy 1 folder to another location in linux:
cp -avr /home/vivek/letters /usb/backup
cp -option1 -option2 source destination

¦-a : Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.
¦-v : Explain what is being done.

¦-r : Copy directories recursively.

16)List all users in linux
cat /etc/passwd

17)ps -ef

t displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [dd-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).

ps --. process status
-e --> The -e option generates a list of information about every process currently running. The -f option generates a listing that contains fewer items of information for each process than the -l option

18)kill a process

In order to find the PID of a process, ps -ef | grep
This ouyput will show the PID.

19)thread dump in /opt/tomcat/logs/catalina.out file by running the below command.
kill -PID `ps -ef | grep catalina | grep -v grep | awk '{ print $2 }'

20) enable ownership to a particular user, recursively to all the files under a folder.
chown -r :

rsync is for syncing files from one di to another:
rsync -azv

¦Recursive mode
¦Preserves symbolic links
¦Preserves permissions
¦Preserves timestamp
¦Preserves owner and group

¦-z is to enable compression
¦-v verbose
¦-r indicates recursive

22)2>&1 --> standard error(2) should be shown in standard Output(1)
/dev/null --> both the error and output should not be shown in anywhere.

writing to /dev/null eliminates the output of a program. Usually cron sends an email for every output from the process started with a cronjob. So by writing the output to /dev/null you prevent being spammed if you have specified your adress in cron.This is the way to execute a program quietly, and hide all its output./dev/null is a special filesystem object that throws away everything written into it. Redirecting a stream into it means hiding an output.The 2>&1 part means "redirect both the output and the error streams". Even if your program writes to stderr, that output will not be shown.2>&1 redirects standard error (2) to standard output (1), which discards it as well since standard output is already redirected.

23)How to increase ulimit open file and user processes in Linux/Centos/RHEL
Note: Know the consequences and understand the requirement, why the ulimit has to be changed?

Max Number of ulimit open file : It's provide open file resource availability in linux

Increase max number of ulimit open file in Linux.

1- Step :  open the sysctl.conf  and add this line  fs.file-max = 65536

vi /etc/sysctl.conf   add end of line
fs.file-max = 65536

save and exit.

2. Step : vi /etc/security/limits.conf  and add below the mentioned

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535
save and exit check max open file ulimit
[root@localhost# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 127358
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Increase max user processes in Linux

Follow the step:

vi /etc/security/limits.conf  and add below the menstioed

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535
and  vi /etc/security/limits.d/90-nproc.conf

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535

24) number of cores:
cat /proc/procinfo
cat /proc/meminfo -> check RAM Size
top --> memory in kb is given, total memory
free -m

25) disk details
df -h

26)Unix Password:
not able to access a server with giver username and password:

check password
if expired, reset password
Task: Change Password For Other User Account

You must login as root user, type the following command to change password for user vivek:
# passwd vivek

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


    vivek - is username or account name.

passwords are stored in shadow files. /etc/passwd

/etc/shadow file fields


(Fig.01: /etc/shadow file fields)

    User name : It is your login name
    Password: It your encrypted password. The password should be minimum 6-8 characters long including special characters/digits
    Last password change (lastchanged): Days since Jan 1, 1970 that password was last changed
    Minimum: The minimum number of days required between password changes i.e. the number of days left before the user is allowed to change his/her password
    Maximum: The maximum number of days the password is valid (after that user is forced to change his/her password)
    Warn : The number of days before password is to expire that user is warned that his/her password must be changed
    Inactive : The number of days after password expires that account is disabled
    Expire : days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying when the login may no longer be used

27)What does the 'c' permission define for permissions, 'crw-rw-rw-'?

in reply:
'c' represents a character device e.g. a serial port or a terminal - note these process data in bits.
'b' represents a block device e.g. hard drive, cdrom etc.. these process data in blocks or bytes.
'l' represents a symbolic (soft) link as in a Windows shortcut
'd' represents directory
'-' represents a file

28) For checking the hostname/DNS/ of a server
nslookup from chef-server
LOgin to that server

29)check linux version:
cat /etc/*-release

30)rebooted the server:(login as root user) -->
shutdown -r time "message"

31)Load Balancer:

32)open gz files in linux
gunzip file.gz

Untar a file
tar -xvf file.tar

for a /tar.xz file use the following file.

33) How to determine whether a given Linux is 32 bit or 64 bit?
uname -m. It seems like the uname -m actually gives

x86_64 ==> 64-bit kernel
i686   ==> 32-bit kernel

35) for linux distribution
lsb_release -a

36) Full permission to a dir
chmod -R 777 dir_name

Change owenrship
chown -R tomcat:tomcat dir_name

37) uname -ar --> list the kernel information
--a --> all
r -> kernel release

to check running server in debug mode or not:
uname --ar | grep -i "debug"

i --> case insensitive

Try uname -m. It seems like the uname -m actually gives --> to check 32/64 bit OS

x86_64 ==> 64-bit kernel
i686   ==> 32-bit kernel
for chef-denver box
[server ~]$ uname -v
#1 SMP Tue Jan 29 11:47:41 EST 2013

SMP = Symmetric Multi-Processors
RT = Real Time

It is a way to identify your kernel version/activated options.

38) check history of the commands executed:
type history

for specific command grep it
history | grep "chef-client"

39)linux daemon --> Disk And Execution MOnitoring

any background process in unix /linux systems. similar in windows are services.

linux filesystems tutorials -->



Anonymous said…
0(zero) to go to start of the file

Popular Posts