check file is there not in linux using if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check file is there not in linux using if statement
# 1  
Old 05-04-2009
check file is there not in linux using if statement

How to check file is there not in linux using if statement ?

Please do put one example if possible.
# 2  
Old 05-04-2009
Quote:
Originally Posted by nskbalu
How to check file is there not in linux using if statement ?

Please do put one example if possible.
What do you mean by file is there not in linux. File is where?

Thanks
NT
# 3  
Old 05-04-2009
CAPT_LOG="/tmp/capt_log"

function touch_files()
check $CAPT_LOG is there, if not touch ${CAPT_LOG}

if [ -f ......???????
# 4  
Old 05-04-2009
Code:
if [ -e $1 ]
then
echo "the file exist"
else
echo "the file does not exists so creating it"
touch $1
fi

run as

./file_exist_check.sh yourfilename


Thanks
NT

Last edited by namishtiwari; 05-04-2009 at 12:30 PM..
# 5  
Old 05-04-2009
Quote:
Originally Posted by namishtiwari
Code:
if [ -e $1 ]
then
echo "the file exist"
else
echo "the file does not exists so creating it"
touch $1
fi

run as

./file_exist_check.sh yourfilename


Thanks
NT
Excellent
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to escape the @ character in an if statement check?

Hi, I am running a shell script that has to verify a password with an if statement. The password has an @ in it. I am having problems getting the if statement to test for the password. The @ causes problem. I tried the standard backslash escape but it did not work for me. How can I do it? I... (2 Replies)
Discussion started by: mojoman
2 Replies

2. UNIX for Beginners Questions & Answers

If statement to check file transfer

Hello Guys, I am trying scp few file within if statement, but getting error, can someone please help to understand, what mistake I am making ? if && ] ; then echo " Files transferred to Log servers successfully. " else echo " One or more file transfer failed over... (10 Replies)
Discussion started by: UnknownGuy
10 Replies

3. Shell Programming and Scripting

How to Check Multiple conditions in IF statement?

I wish to check two conditions inside the if statement Condition 1: The two file contents should be identical // using cmp command for this. Condition 2: The two filenames should NOT be the same. This is what i did in vain. if ]; then where entry1 and entry2 are ls *.txt | while... (7 Replies)
Discussion started by: mohtashims
7 Replies

4. Shell Programming and Scripting

Check the file status in Linux.

Hi All, I have a simple problem . I am pulling the file from a remote server througha simple file transfer protocal (ftp ). But I wanted to check before pulling the file ,whether the file is being written or in use by some other process and if so i dont want to pull the file and wait for... (1 Reply)
Discussion started by: ptappeta
1 Replies

5. Shell Programming and Scripting

Linux Shell Script to check for string inside a file?

This is what I have so far grep -lir "some text" * I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access. How can this be done? (3 Replies)
Discussion started by: mapleleafs89
3 Replies

6. Shell Programming and Scripting

IF statement to check file exists

Hi All, If i run below copy command, it works absolutely fine, /opt/csw/bin/scp axetlxyz01:/opt/data/test/QURIES* ./input I want to make the above line better, by adding an IF statement, want to check if there is any file exists with name QURIES*.* then i need to copy that. if ... (7 Replies)
Discussion started by: rkrgarlapati
7 Replies

7. Shell Programming and Scripting

using if statement to check file size

Hi, Am trying to execute certain commands if the condition satisfied, but i feel i am making some mistakes in the usage of if statement here is the code #!/bin/ksh SIZE=$(ls -ltr /aemu/ws/DN.txt | tr -s ' ' | cut -d ' ' -f 5) filename=`TZ=CST+24 date +%Y%m%d` ZERO=0 if then cp... (5 Replies)
Discussion started by: aemunathan
5 Replies

8. Shell Programming and Scripting

How to check if a file exists using the if statement

Hi, I'm trying to write a bit of code that will check if a file exists and then archives the file Im trying to use the following if statement without success.. if then mv filename archive/filename else echo "no filename exists" fi Should the file name be... (3 Replies)
Discussion started by: Jazmania
3 Replies

9. Shell Programming and Scripting

How to get path and check in if statement

Hi, I was wondering if it possible to get the path of a variable and compare that to something. Basically I want to write a script that checks if my $JAVA_HOME is correct and if not then it sets it. So far I have... if ] then export JAVA_HOME='/pathhere' echo JAVA_HOME='/pathhere' fi ... (6 Replies)
Discussion started by: eltinator
6 Replies

10. UNIX for Dummies Questions & Answers

check a statement -- yes/no

this statement "Be sure to have /usr/bin before /usr/local/bin in your $PATH" is because, if u have any files in bin directory, /usr/local/bin will be the first place to look at instead of /usr/bin. BUT, /usr/local/bin has one more descending directory to go , therefore /usr/bin has to come before... (2 Replies)
Discussion started by: yls177
2 Replies
Login or Register to Ask a Question