CentOS Linux Server Guide

Centos Linux Command Line Operation

Using "&&" symbol

 

In contrast with ";" symbol, you use this symbol to ensure both only first command is success then the system will only proceed with second command.

 

SYNOPSIS

command && command

 

In the following example, first we change to /demo, then we list the contents at /demo directory. Note: first command is valid then we proceed with second command.
cd /demo &&  ls -l

total 44
drwxr-xr-x 2 root root 4096 Nov 29 17:19 Dir_empty
-rw-r--r-- 1 root root 64 Nov 30 01:22 error.txt
-rw-r----- 1 root root 0 Nov 30 00:10 jane
drwxr-xr-x 2 root root 4096 Nov 28 16:00 myDir
drwxr-xr-x 2 root root 4096 Nov 28 15:43 newmyDir
-rw-r--r-- 1 root root 8 Nov 30 00:59 test.txt

 

 

 

In the following example, first, we change to /etc/passwd (which is file,NOT a directory), then we ls all the files and folders. Note: first command is fail, the system will stop processing second command and issue us with stderr (error output to screen)

cd /etc/passwd && ls -l

-bash: cd: /etc/passwd: Not a directory
 

 

Back to Command Line Operation



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy