Saturday, August 13, 2022

Bash - How to Check if a File or Directory Exists in Mac/Unix

 


How to Check if a File or Directory Exists using Bash?


Using IF statement

FILENAME=/etc/conf.yml
if [ -f "$FILENAME" ]; then
echo "$FILENAME exists."
else
echo "$FILENAME does not exist."
fi

Without using IF statement

[[ -f /etc/conf.yml ]] && echo "$FILENAME exists."

Bash/Unix/Mac - File permissions

File permissions - Bash/Unix/Mac


Format is 421

4 - read

2 - write 

1 - execute


The following table shows each permission is assigned a value.

NumberOctal Permission RepresentationRef
0No permission---
1Execute permission--x
2Write permission-w-
3Execute and write permission: 1 (execute) + 2 (write) = 3-wx
4Read permissionr--
5Read and execute permission: 4 (read) + 1 (execute) = 5r-x
6Read and write permission: 4 (read) + 2 (write) = 6rw-
7All permissions: 4 (read) + 2 (write) + 1 (execute) = 7rwx



$ chmod 755 filename.txt

$ chmod 622 filename2.txt

$ chmod 


Shows how much memory is free

$ watch free -h 

Bash Command Quick Reference

 Bash Command Quick Reference


ls => list of files in a folder / directory 

$ ls

 

List of files with permission (long format)

$ ls -l 


List of all files in a directory

$ ls -a 


cd => change directory

$ cd <folder>


Go back to home

$ cd 

Or 

$ cd ~


Create or make a directory or folder

$ mkdir Junk


Locate or search a file.

$ locate filename


To update system db

$ sudo updatedb

"Which" command is used to find other commands

$ which cal

(cal represents calendar command)

Use "history" command to display the history of all the commands you used

$ history

To know what the command does (use whatis command)

$ whatis cal


Copy a file use cp command (cp sourcefile newfile)

$ cp ~/.bashrc bashrc

Move a file (this overwrites and deletes the source file)

$ mv sourcefile targetfile.bash

Remove a file (rm command)

Cat command - "cat" command is used to read the file and display in the monitor

$ cat file1 file2

(merge file1 and file 2 content and shows in the screen)

$ cat >> file2

Append text

$ cat > file3 

(new file)

$cat 

Nano => 

$ nano


Copy the list of files and access from root directory and write it to a file called out.txt

$ ls -al / > out.txt


To see the output of a file used below command

$ less out.txt

Sudo => if we need to run a command with elevated privileges / access.

$ sudo updatedb

$ sudo -s

Exit

$ su - cindy

(This command will switch user to cindy and do necessary work)

$ exit

logout


This appends the output to all.txt

cat *.txt >> all.txt

This overwrites all.txt

cat *.txt > all.txt



Kill a process or application

$ killall firefox 

Bash Commands

Youtube videos to learn Bash commands (Basics)

Beginner's Guide to the Bash Terminal





Intermediate Bash command training


Intermediate Bash Commands (grep, sed, awk, tar, less, gzip)


MacBook - How to take screenshot(s) in MacBook

 How to take screenshot(s) in MacBook





Please see the below link for more details

https://www.take-a-screenshot.org/mac.html



--------------------------------------------------------------------


Kill a process or application

$ killall firefox

Thursday, August 4, 2022

Cron - for Scheduling a Job in Apache Airflow

 

CRON format is used to schedule a Job in Apache Airflow.


Schedule="0010**0"


Field            Allowed values

—–                    ————–

minute            0-59

hour                     0-23

day of month     0-31

month          0-12 (or names, see below)

day of week     0-7 (0 or 7 is Sun, or use names)




Please find the following links for more details

Friday, July 23, 2021

Varada's - My first app (Apple mobile app)


This is my first app. I created it to get the app experience.

Technologies used Xcode and Swift for development.


For app support, please contact varadarajaboopathi@gmail.com