Тёмный

Shell Scripting Tutorial for Beginners 6 - File test operators 

ProgrammingKnowledge
Подписаться 1,8 млн
Просмотров 221 тыс.
50% 1

For more detailed Tutorial visit - goo.gl/vn9xIb
Shell Script has many operators that you can use to test different aspects of a file. For example, you can use the -e operator to ensure that a file exists before deleting it. Or, you can check that a file can be written to before appending to it. By checking the feasibility of the impending file operation, you can reduce the number of errors that your program will encounter.
My Website - www.codebind.com
My Blog - goo.gl/Nd2pFn
My Facebook Page - goo.gl/eLp2cQ
Google+ - goo.gl/lvC5FX
Twitter - / programmingknow
Pinterest - goo.gl/kCInUp
Text Case Converter - goo.gl/pVpcwL
Epoch Timestamp Converter - goo.gl/Zedjo5
Decimal - Binary - Hexadecimal Converter - goo.gl/rkX3JE
8-bit Checksum Calculator - goo.gl/inxvIT
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqcm.net/r1KEj
Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
Kotlin Android Development Masterclass - bit.ly/2GcblsI
Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
★★★ Follow ★★★
My Website - www.codebind.com
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

Опубликовано:

 

10 мар 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 62   
@MommaMolly
@MommaMolly Год назад
These videos actually are helping me to understand. I am starting to believe. Thank you so much.
@apporvaarya
@apporvaarya 5 лет назад
loved all videos till yet.. still a long way to go :)
@Xieerqi
@Xieerqi 6 лет назад
On 7:10 mark author of the video states that character special file is a normal file which contains text, while block file is file like video or picture file. That's not true. Block files are used to represent partitions of a hard drive, usb sticks, memory devices,etc. Character devices are typically consoles, like /dev/tty1, or devices that generate characters such as /dev/zero. Thus, -b flag will not work on video file but will work on partition file such as /dev/sda1. Video and text files are still considered regular files, not character or block.
@ghost101049
@ghost101049 3 года назад
As someone who is new to scripting, thank you. I like the author's videos, but hopefully he can correct that. I thought block was always about storage like partitions or storage groups.
@deepakdoer8507
@deepakdoer8507 2 года назад
Thanks for the correcting it.
@user-rp6xi4il5z
@user-rp6xi4il5z 6 лет назад
i excute these command ,and there are some problems,i have solved it,hope i can help you guys; every time i execute,the terminal says “if [-e test] :command not found; Pay close attention,when we type in if statement , if we type in a space after the first square bracket [,we must type in the other space before the second square bracket]
@randomupload6250
@randomupload6250 5 лет назад
Thanks :)
@toniboix6480
@toniboix6480 4 года назад
Great tip! I have just faced that issue right now. Thank you
@subhambairagi5642
@subhambairagi5642 2 года назад
Use dollar '$' sign to declare that it's a variable.
@Deva2596
@Deva2596 9 месяцев назад
thanks :)
@muhammadfaizan2461
@muhammadfaizan2461 7 лет назад
Nice...Very understandable..Thankx
@3rg1s
@3rg1s 7 лет назад
Very well explained thnx
@SoftwareDeveloper2217
@SoftwareDeveloper2217 15 дней назад
Common Misconceptions- Character special files are associated with character devices, not normal text or data files. Block special files are associated with block devices, not binary files, picture files, music files, or video files.
@lovelyfamily4886
@lovelyfamily4886 Год назад
Thank you sir
@sayaliborse9999
@sayaliborse9999 4 года назад
Sir can you please help me with how many flags are there to exicute different situations
@Andrzej3935
@Andrzej3935 4 месяца назад
Thanks!
@nicolasvillafan
@nicolasvillafan 5 лет назад
Ok I was wondering what program those flags are related to and look online to find that they belong to the test command.. I think it would be nice to clarify that.
@UnknownSend3r
@UnknownSend3r 4 года назад
Very true.
@amitdixit2635
@amitdixit2635 5 лет назад
In this script( File test operators) whenever i executed my script and press enter without give any filename why it is showing result found? amitdixit:~ root# ./hello.sh enter file name : found
@sunilvarma3051
@sunilvarma3051 6 лет назад
i am trying the above said comments in Putty and i am getting errors like below if i use -e or -f in if condition /6_readfile.sh: line 5: [-f: command not found /6_readfile.sh: line 5: [-e: command not found For putty do i need to change something in the scripts. could you please advice #! /bin/bash echo -e "enter the name of the file :\c" read file_name if [ -e $file_name ] then echo "$file_name is present" else echo "$file_name is not present" fi
@anuragkubade6511
@anuragkubade6511 2 года назад
How to check for the multiple files? I tried with -a option with read but no luck.
@jamesraphael8473
@jamesraphael8473 Год назад
Thanks for the video but the -e parameter for file test operations means file size is greater than 0. And -f test for the existence of the file Well explained video. Also instead of using \c and -e it's easier to use just -n after typing echo (e.g. echo -n "Enter...." ) to get the cursor remain on the same line as the input string
@TheZakev
@TheZakev 3 года назад
Why not to use: It gives you the same result? read -p 'Enter your file: ' file if [[ -e $file ]] ; then echo "$file found" else echo "$file not found" fi
@K8JD
@K8JD Год назад
what is -p indicates like
@ajaidx
@ajaidx 4 года назад
HI , is there any file test operator flags to print out the exact location of the file /directory ?
@devdattakulkarni8056
@devdattakulkarni8056 3 года назад
Pwd
@abdulhaseeb3746
@abdulhaseeb3746 5 лет назад
can we use multiple flags simultaneously in a single if statement ??? anybody ??
@tupbai
@tupbai 4 года назад
how to check a file has exist or not without input he file name, then how to write the file name to check on the script
@raviteja5542
@raviteja5542 6 лет назад
hello sir, i want to know how to test a file whether exist or not when the file name is given from command line arguments not by us. how program for it. thanks in advance
@achrafoukouhou1016
@achrafoukouhou1016 6 лет назад
if [ -e $1 ] then echo "$1 found" else echo "$1 no found" fi and when you use terminal write sh file.sh myfile
@charlesklein7232
@charlesklein7232 4 года назад
were do you get the details "Shell Script" information? the rules? the notes? a book? is their a book of Ubuntu shell scripting with the details of the commands and the "FLAGS."
@pulsar17
@pulsar17 4 года назад
The UNIX Programming Language by Brian Kernighan and Rob Pike is a great book to start learning. (Although it's a UNIX book and I guess published >30 yrs ago)
@faizshaikh7972
@faizshaikh7972 7 лет назад
ECOMMERCE BASED...
@R5417
@R5417 2 года назад
The then keyword is showing error in the online editor can anyone tell me how to resolve it?
@aman31dec
@aman31dec Год назад
I am getting indentation error on "else", and without using else, there is an error on "fi" #! /usr/bin/bash count=10 if (($count>10) then echo "Number is greater than 10" else echo "Number is lesser than 10" fi
@K8JD
@K8JD Год назад
and forgot u just put paranthesis bracket right side ) not get any error
@kshamendermishra6213
@kshamendermishra6213 2 года назад
that -e option is not working , its printing as echo said.
@qfong97
@qfong97 Год назад
How are you giving all this info for free? More than my college intro to Linux class has given me already.
@mohamedmoharam8677
@mohamedmoharam8677 4 года назад
i have some problem here if [-e $filename] :command not found;
@sayaliborse9999
@sayaliborse9999 4 года назад
Try putting space between brackets
@mohamedmoharam8677
@mohamedmoharam8677 4 года назад
@@sayaliborse9999 yes u right thank u for ur reply
@user-rp6xi4il5z
@user-rp6xi4il5z 6 лет назад
what are block special file and character special file,who can help me
@abhishekpes
@abhishekpes 5 лет назад
read -p "Enter the name of the file : " file_name
@akhilmunjolil9474
@akhilmunjolil9474 6 лет назад
😍😍😍
@akshaychanna007
@akshaychanna007 4 года назад
-r -w -x for read write execute permission right..?? but whose permission user or group or other .?
@nurulizf_5191
@nurulizf_5191 4 года назад
akshay channa -r permission for user, -w for group and -x for other
@shikhar2811
@shikhar2811 4 года назад
+akshay channa it checks permission for the user. Suppose if you write the script to check whether a file has read permission, And you set the permission of that file to -w-rw-rw- then the script will return that "read permission is not available" of whatever string you put in the script .... Although read permission is given for group and others
@TheAuroravinod
@TheAuroravinod 3 года назад
what is regular file ?
@harindrabalanagireddy9059
@harindrabalanagireddy9059 3 года назад
Block special & character special file condition not working
@atiknadaf18
@atiknadaf18 3 года назад
how to check if directory is empty or not.
@nephilimedg134
@nephilimedg134 3 года назад
for mac use if [[Statement]] fi
@faizshaikh7972
@faizshaikh7972 7 лет назад
SIR MAKE AN PROJECT IN ASP.NET MVC ....
@mamtachahal1277
@mamtachahal1277 4 года назад
Also instead of echo before a read you can use the prompt flag of read echo -e "...\c" read file_name you can use read -p "..." file_name
@sathyamoorthy7279
@sathyamoorthy7279 4 года назад
Im a beginner is my style of learning fine ? #! /bin/bash echo -e "Enter the file name : \c " # -e to enable \c for cursor to stay on same line read file_name if [[ -s $file_name ]] # -s flag for checking empty files #if [[ -d $file_name ]] # -d flag for directory exist or not #if [[ -f $file_name ]] # -f flag for file exist an regular file #if [[ -e $file_name ]] # -e flag for check file exist in the directory then echo "$file_name exist/ not empty " else echo "$file_name doesn't exist/ empty" fi # [[ -e -f -d -s -r -w -x ]] flags exist
@GOODBOY-vt1cf
@GOODBOY-vt1cf 2 года назад
5:34
@hamdamboyurunov6034
@hamdamboyurunov6034 4 года назад
echo -e "Enter the file name: \c" read filename if [ -r $filename ] && [ -w $filename ]; then echo $filename " can read and write " else echo $filename " cannot read and write. " fi
@faizshaikh7972
@faizshaikh7972 7 лет назад
PLEASE....
@arjungowda3728
@arjungowda3728 5 лет назад
Is any Flag to find path of file or directory
@rogeliovillafana7282
@rogeliovillafana7282 5 лет назад
-d
@GOODBOY-vt1cf
@GOODBOY-vt1cf 2 года назад
5:26