Essential Linux Commands for File Management and Scripting

Specify the Linux command which qualifies the screen, with the command ls, list the contents of the directory /root/test, where file names are in quotes and separated by commas. ls -Q -m /root/test

Specify the Linux command that allows listing all the subdirectories in the current directory that have permission to read, write, and execute for the owner, and read and execute for the group. ls -l | grep ^drwxr-x

Specify the Linux command that allows making the C shell the default shell for root. chsh -s /bin/csh

Write a shell script that can receive a file and directory as arguments. The script should verify that such arguments actually correspond to a file and directory, respectively. The script should check and report if the file exists in that directory, but the script should copy the file into the directory.

/bin/bash 
clear
if test -f $1
then
if test -d $2
then
ls $2 | grep -w $1
if test $? -eq 0
then
echo -e "File $1 exists in $2 "
else
cp $1 $2
fi
else
echo -e "Invalid directory "
exit
fi
else
echo -e "Invalid file "
exit
fi

Create a file called personas.dat, where the fields that make up each record include name, weight (in kilograms), and height (in meters). The file has the character # as the field delimiter, so for example, the file personas.dat could have the data: Juan # 80 # 1.75
Paulina # 65 # 1.6

Write an awk program, called listado_imc, allowing personas.dat to read the file and generate a list of people with a normal BMI (Body Mass Index). For values between 18.5 and 24.99, BMI is considered normal. BMI is calculated as BMI = weight / (height)2.

The list shall have the following format: Normal BMI Listing
Nombre IMC

BEGIN {FS = "#"; OFS = "\t";} 
{
imc = $2 / ($3 * $3);
if (imc >= 18.5 && imc <= 24.99)
printf "%-s\t%.2f\n", $1, imc;
}

The implementation should be: awk -f listado_imc personas.dat

Given the following contents of the PATH environment variable:
/usr/local/bin:/bin:/usr/bin:. If I have a command called list in the current directory and another called the same way in the directory /usr/bin, what would be selected to run at the prompt simply list? The command list is executed in /usr/bin, then the current directory (.) appears after /usr/bin in the PATH.

Write a shell script that can receive two files as arguments. The script should validate that the parameters are actually received and that the first file (input file) given as an argument was not empty. Then you must save in another file (output file) lines that begin with any letter (upper or lower case) from the input file. /bin/bash
clear
if test -s $1
then
if test -f $2
then
grep ^[a-zA-Z] $1 >> $2
else
echo -e “$1: Invalid file ”
exit
fi
else
echo -e “$1 file does not exist or is empty ”
exit
fi

Specify the Linux command that allows searching and deleting, without confirmation, all empty regular files whose names begin with the letter a and are found in the /root/test. find /root/test -name ‘a*’ -size 0 -type f -exec rm -f {} \;

Create a file, palabras.txt, containing a different word on each line. Specify the Linux command that allows extracting from the file palabras.txt all words that begin and end with a vowel (upper or lower case). Should be created with any editor palabras.txt
grep ‘^[aeiouAEIOU]’ palabras.txt | grep ‘[aeiouAEIOU]$’ > words.txt

Specify the Linux command that allows the creation of the alias list that allows clearing the screen, setting the date and time of day on separate lines, and listing the permissions of all files in the directory. alias list=’clear; date +%D; echo; date +%T; ls -al’

Using piping, type the command LINUX allowing for the amount of regular files (or standard files) that exist within the current working directory. ls -l | grep ^- | wc -l

Create a file called notas_curso, where the fields that make up each record include name, student surname, first note, second note, and third note. The file has the character , as the field delimiter, so for example, the file may have notas_curso data:

Juan Perez, 3.5, 4.7, 5.3
Pauline Fabres, 2.5, 4.7, 3.4

Write an awk program, called listado_aprobados, allowing on-screen display of a list of approved students (average greater than or equal to 4.0). The list shall have the following format: List of Approved
Apellido Nombre Promedio

BEGIN {FS = “,”; OFS = “\t”;}
{
average = ($3 + $4 + $5) / 3;
if (average >= 4.0)
printf “%-s\t%-s\t%.1f\n”, $2, $1, average;
}

The implementation should be: awk -f listado_aprobados notas_curso

Provide LINUX commands for fixing the appropriate environment variables so that the command history includes the date and time of execution of commands, and the elimination of duplicate entries in the historical ALL command history file, respectively.

Just edit the HISTCONTROL and HISTTIMEFORMAT variables in the file .bash_profile of the user, for example:export HISTTIMEFORMAT=’%F %T’
export HISTCONTROL=erasedups

Consider a company, founded by its parent company and three subsidiaries. Due to connection problems from a parent branch, it has decided to constantly test the IP addresses of those branches.
Write a shell script, called testIP, to complete a log file containing the evidence of connectivity from headquarters to all branches. Connectivity testing will be undertaken every 5 minutes, 24 hours a day, and the results must be kept in the file testIP_sucursales.log, along with the date and time of the connectivity test performed. The IP addresses of branches should be provided to the shell script in a file whose name will be passed as an argument to the script and the format of which is simply an IP address (which is going to be tested) on each line of the file.

/bin/bash 
clear
while true
do
for ip in $(cat $1)
do
echo -e +--------------------------------+ >> testIP_sucursales.log
date +%D %T >> testIP_sucursales.log
ping -c 3 $ip >> testIP_sucursales.log
done
sleep 300
done

Write a shell script, called mostrar_lineas, using while, displaying all non-empty lines, along with the line number, from a file read from any keyboard. /bin/bash
clear
echo -e “File: “;
read file
i=1
while read line
do
if test ! -z “$line”
then
echo -e “$i\t$line”
i=$(echo $i + 1 | bc)
fi
done < $file