#!/bin/bash
echo -n "Enter directory name:"
read x
[[ ${x:='xX'} == 'xX' ]] && echo "error: No filename" &&
exit 0
mkdir --parents "/tmp/$x" 2> /dev/null
echo -n '' > "/tmp/$x/$x.txt"
echo "Enter text. Type 'STOP' on a line by itself to terminate."
while read y
do
[[ "$y" == "STOP" ]] && break;
echo "$y" >> /tmp/"$x"/$x.txt
done
a=$(wc -c "/tmp/$x/$x.txt" | cut -f1 -d' ')
echo
echo "file: /tmp/$x/$x.txt has $a characters"
exit 0;
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stddef.h>
#include <sys/stat.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dip;
struct dirent *dit;
struct stat sb;
int i = 0;
if(argc < 2)
{
printf("Usage: %s <directory>n", argv[0]);
return 0;
}
if((dip = opendir(argv[1])) == NULL)
{
perror("opendir");
return 0;
}
printf("Directory stream is now openn");
while ((dit = readdir(dip)) != NULL)
{
i++;
stat(dit->d_name,&sb);
printf("%u t%sn",sb.st_ino,dit->d_name);
}
printf("No. of Files in directory are: %i n", i);
if(closedir(dip)== -1)
{
perror("closedir");
return 0;
}
printf("nDirectory stream is now closedn");
return 1;
}
#include <stdio.h>
#include <signal.h>
void sigproc(void);
main()
{
signal(SIGINT, sigproc);
printf("This program catches ctrl-c(SIGINT) signal for
first time and exit on pressing ctrl-c againn");
for(;;);
/* infinite loop */
}
void sigproc()
{
signal(SIGINT, sigproc);
printf("you have pressed ctrl-c n");
(void) signal(SIGINT,SIG_DFL);
}
on Linux:
man 2 signal
for signum use SIGINT
#!/bin/bash
for x in $(echo $PATH |sed "s/:/ /g")
do
echo "Directories in your PATH which you cannot write are:"
echo $(find $x -perm /666 -type d -maxdepth 0 2>/dev/null
|xargs ls -dl | grep -v $USER)
done
exit 0;
this script is written for bash :
echo Enter the string
read s
echo $s > temp
rvs="$(rev temp)"
if [ $s = $rvs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
echo Enter the string
read s
echo $s > temp
rvs="$(rcs temp)"
if [ $s = $rcs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
#!/bin/bash
for x in $(echo $PATH |sed "s/:/ /g")
do
echo "Directories in your PATH which you cannot write are:"
echo $(find $x -perm /666 -type d -maxdepth 0 2>/dev/null
|xargs ls -dl | grep -v $USER)
done
exit 0;
Using sh -x script argument you can debug(-x option).
Bash shell offers debugging options which can be turn on or
off using
set command.
=> set -x : Display commands and their arguments as they are
executed.
=> set -v : Display shell input lines as they are read.
Hope this answers your question.
We can debug only by $? which contains the returned value
of last executed command.
If $? contains 0 value then command run successfully other
wise error occured while running command
create script test.txt with | seperated
The below commands can be used to get the fields values:
awk -F"|" '{print $1}' test.txt
cat sri.txt | cut -d"|" -f1
Different types of command using delimiter :
1. cut -d "|" -f6 emp.lst
d : delimiter or field separator
2. sort -t "|" -nk6 emp.lst
t : delimiter or field separator
3. awk -F "|" '{print $6}' emp.lst
F : delimiter or field separator
For gdb in linux/unix Gnu Debugger is available. Please
read the mannuals for gdb.
man gdb
If it is a shell script use #!/bin/ksh -x
use record/playback feature but won't be able to go too far
with it
test -f $(find /var/log/messages -name "file.log" )
echo $?
If it returns 0 means passed
if 1 means not passed
tail -f /var/log/messages provided all the messages are
appended to the log.
1>Interactive mood:--
As Shell scripting is working like as interpreter (not
likely compiler) in a interactive mood.
2> Less time:--
it will take less time than C or C++ or other file to process.
Shell is a command interpeter. If we want to run multiple
commands at a time through a script file then it is called
shell scripts.
Generally we will write these to set certain environmental
variables in unix and run some other programs.
The shell scripts utility programs to perform certain tasks
in unix environment.
this site is for knowledge sharing friend. not for fake
things. use this site as it meant for.
$# - Number of argument passed
$* - Array of arguments given (or) passed arguments as an array
$# - number of command line arguments or positional
parameters
$* - All of the positional parameters, seen as a single word
The Unix category on takluu.com is designed for IT professionals and developers preparing for interviews that require a strong understanding of Unix operating systems. Unix has been the backbone of many enterprise systems due to its stability, security, and multitasking capabilities.
This section covers key topics such as Unix file system architecture, shell scripting, process management, file permissions, user management, and networking commands. You will also learn about vi editor, cron jobs, package management, and system monitoring tools.
Interview questions often assess your proficiency in writing shell scripts, automating tasks, troubleshooting system issues, and managing user permissions. Candidates may be tested on commands like grep, awk, sed, find, and piping techniques, as well as understanding system boot processes and kernel basics.
Roles such as Unix Administrator, DevOps Engineer, System Engineer, and Backend Developer often require expertise in Unix environments. This category also includes best practices for security hardening, backup strategies, and performance tuning in Unix systems.
At Takluu, we offer detailed tutorials, practical exercises, and interview question sets that will help you build confidence and excel in your Unix-related interviews.
Whether you’re a beginner or looking to deepen your Unix skills, this category equips you with comprehensive knowledge to manage Unix systems efficiently and advance your career.