I’ve got a bash command to find the largest file in a sub-directory. I’d like to save the output to a variable to use it with other commands. bigile=$(find /path/to/directory -type f -exec du -Sh {} + | sort -rh | head -n 1) Unfortunately, this saves both the file size and the filepath. If I pass …
Tag: bash
Error When trying to push ssh keys into github from bash script
I am working on a script that creates ssh keys and puts them into github using bash. I am running into this error when running this function.. I want a way to generate ssh keys and put them into github from terminal within my script. Error: { “message”: “Bad credentials”, “docume…
Does an argument after a redirection do anything?
Is any argument after a redirection ignored, or does it have any unintended consequences? I was surprised to find that a typo I made in my bash script made absolutely no difference because it was specified after a redirect. E.g. I expected it to complain about something like this But it doesn’t throw an…
Bash script to transfer all files from current directory to specific directory based on name
I have these files: 100-1.jpg 100-2.jpg 200-1.jpg 200-2.jpg I want these to be transferred to specific folder based on filename 100/100-1.jpg 100/100-2.jpg 200/200-1.jpg 200/200-2.jpg How do I do this? What I have tried so far how do I know I cut the string before the dash e.g 200-1 to 200 and store in a vari…
ack outputs nothing using crontab in linux
ack outputs nothing using crontab in linux. In the crontab file (edited with sudo crontab -e): And cat /ext/test110.sh will show After cron, there are 1.t and 2.t in /ext cat 2.t will output /usr/bin/ack; However, nothing in 1.t. If I run ack “localhost” /etc/hosts > /ext/3.t in bash (4.3.30) o…
How to run docker rmi $(docker images -a -q) in Jenkins as part of ssh script
I am building a Jenkins jobs to build docker container on AWS EC2 instance and this is a sample of a Jenkins script that is giving errors: When I build this job in Jenkins, it fails with following error on output console : “docker stop” requires at least 1 argument(s). See ‘docker stop ̵…
How to convert to / get RFC822 date in bash/linux?
Looking at date’s man page, I couldn’t find a standard way to convert to rfc822 (eg: from unix timestamp). I took a brief look at the spec, but I don’t know enough about the subject matter to get the format right. Is there a easy way to convert to rfc822 with standard linux terminal tools? A…
How to get Date Month values in linux date command as integers to work on
I want to convert date and month as integers. for example. if the current date as per the command “Date +%m-%d-%y” output, is this 09-11-17 Then I am storing the $cur_day will give me 11 and $cur_month will give me 09. I want to do some operations on the month as 09. like i want to print all the n…
Listing files with numeric names
How do I list files that have only numeric names e.g I have tried ls -l [0-9]* but this seems to bring all file names that start with a digit and can have anything in their name after a digit. Answer First, turn on Bash’s extglob option: Then use this pattern: Read more about extended pattern matching i…
Awk in loopwith different file
I have four files and want to run a awk code on each file. But this code is not working. My code: Answer Awk can work with multiple files no need of for syntax will be like this or In your case To correct your existing code change To