Bash is a free shell for Unix-like operating systems, from the GNU Project

learn more… | top users | synonyms

34
votes
9answers
22k views

Unix: ls, how to sort first directories then files etc

I would like to use ls command to first show direcotries and then files. I tried ls -la | sort -k 1 But I got a wrong order.
0
votes
1answer
21 views

How can I move a specific folder if there is a file with the same name in bash script?

I'm trying to write a shell script that finds a specific file and moves it to a folder. #!/bin/sh echo -n "/home/cosmoretro/movie/" read text2 while : do echo -n "Ara:" ...
0
votes
1answer
21 views

insert complex line in html file from the command line/bash script

I use a bash script to add a javascript file to a directory, but after that I need to insert into the index.html this line at between line 30 and 31. <script type="text/javascript\" ...
6
votes
4answers
8k views

How to get the full path of a file in bash?

I would like an easy way to get the full path to a file. I currently type this: echo `pwd`/file.ext Trying to shorten it, I made a bash alias: alias fp='echo `pwd`/' But now if I type fp ...
5
votes
3answers
189 views

Why does this bash command take up all space on device?

I'm a little new on searching via bash, so feel free to give me suggestions on the methods to use instead of this, which I'll never use again. I'm searching for occurances of a string, recursively in ...
5
votes
2answers
3k views

How to avoid tilde ~ in Bash prompt?

I would like to remove the tilde from displaying within the PS1 variable. My current PS1 string: PS1="\h:\w\n$" And the prompt looks like this: lnx-hladky:/tmp/plugtmp $ I don't like that the ...
0
votes
0answers
10 views

Print Windows mapping of root path in MSYS Bash

In MSYS Bash I get: $ cd ~ $ pwd /c/Users/antonio but: $ cd / $ pwd / Can I get the full Windows absolute path from Bash?
0
votes
2answers
901 views

GNU Dialog and UTF-8 characters

I'm using GNU dialog in one of my lengthy shell scripts. One of the areas I've got problems with is when I'm asking for an inputBox where the user can type a book's title, mostly in French. In this ...
0
votes
1answer
32 views

Find 350ms in traceroute logs?

So I have a bash script that creates logs like this: traceroute to -------, 30 hops max, 60 byte packets 1 router.Belkin (192.168.2.1) 2.275 ms 2.263 ms 2.249 ms 2 ------- 16.961 ms 21.060 ms ...
1
vote
1answer
1k views

Mountain lion and git-completion

I have ML with Xcode installed tools (git coming from there). Later I've installed brew and install bash-completion, but git commands still not auto-completed. Brew has no such package. Google does ...
0
votes
1answer
20 views

Script won't loop through files like planned

I got this script that loops through log files, but I changed something ant dot doesn't work: #!/bin/sh n= while true do fname="trace$n.log" [ -f "$fname" ] || break n=$(($n+1)) done ...
3
votes
2answers
1k views

How do I use the terminal SCREEN when chrooted?

How do I allow a user to use SCREEN on a chrooted user? I have tried everything but I keep on failing. I need the user to be able to use SCREEN when they are logged in bash as a chrooted user.
3
votes
2answers
34 views

Is there a way to create a command line wrapper for a bash file?

The title says it all. I would like to type "run" in the command line and it would execute /pathtoscript/script.sh. Thank you!
0
votes
2answers
77 views

What does the * mean next to a filename in the ouput of the command ll? [duplicate]

I have a doubt related the output of ll command. When, in my shell, I execute the ll command I obtain this output: -rwxrwxr-x 1 andrea andrea 104215 ott 15 15:56 atmosfs* Why I have the * next to ...
6
votes
5answers
5k views

How can I sort all files by size in a directory?

How can I display the files in a unix directory sorted by their human readable size, going from largest to smallest? I tried du -h | sort -V -k 1 but it does not seem to work.
0
votes
2answers
39 views

How to make a bash script wait and then continue running?

So I have a .sh script. I would like to wait 25 minutes and then continue running, NOT repeat. Its something like this: #!/bin/bash /bin/bash ~/path/script.sh I want it to kill a process after ...
5
votes
3answers
6k views

How can I remove files containing whitespace recursively?

I'm having some trouble with this command under bash in Ubuntu: rm $(find . -name "*.exe") My aim is to remove, recursively, all files ending in .exe. But some files have white spaces and this ...
0
votes
1answer
19 views

pass arguments to alias then disown

I am trying to create a simple alias: alias draw="pinta &> /dev/null & disown" The intent here is pretty obvious. My problem is that whenever I pass an argument, I get bash: disown: ...
1
vote
2answers
33 views

Why does this gpg command in a script behave differently when it's pasted into a shell?

Here is a script which symmetrically encrypts/decrypts a file with two different symmetric ciphers in sequence. #!/bin/bash if [ "$#" -ne 2 ]; then echo "Arguments: enc|dec filename" exit fi ...
4
votes
4answers
2k views

Chmod equivalence of +x and 0755

Just curious, are these two completely equivalent? chmod +x file chmod 0755 file Thanks :-)
6
votes
4answers
9k views

How to compare file timestamps in bash?

How do I compare the timestamp of two files? I tried this but it doesn't work: file1time=`stat -c %Y fil1.txt` file2time=`stat -c %Y file2.txt` if[$file1time -gt $file2time]; then doSomething fi ...
-1
votes
0answers
37 views

Subversion (SVN) Hookscript for commit messages change (pre-revprop-change) with log

because I couldn't find a useful hookscript for pre-revprop-change with logging and I think my script is a good start point for others, here it's. #!/bin/bash # Requires # Bash (tested with 4.1.2) # ...
55
votes
13answers
17k views

Add directory to $PATH if it's not already there

Has anybody written a bash function to add a directory to $PATH only if it's not already there? I typically add to PATH using something like: export PATH=/usr/local/mysql/bin:$PATH If I construct ...
2
votes
1answer
28 views

Hook into “command not found” handler in Ubuntu

I want to hook into the handler for command not found wim@SDFA100461C:~$ thing No command 'thing' found, did you mean: Command 'tping' from package 'lam-runtime' (universe) Command 'thin' from ...
0
votes
1answer
55 views

screen capture full webpage rendered with firefox or chrome

i'm trying to think of a solution that will let me take full page screen shot of a website via a bash script. so far i have tried gnome-web-photo but it doesn't render the webpages correctly. next i ...
1
vote
1answer
33 views

How to make a bash write to trace.log, trace1.log, etc.?

I am making a script and would like to write it to another file if that one exists? traceroute google.com > trace.log Any help would be appreciated. Also, i am a newbie, so an example would be ...
13
votes
2answers
2k views

Unix: Files starting with a dash, -

Ok, I have a bunch of files starting with a dash, -. Which is not so good... and I want to rename them. In my particular case I would just like to put a character in front of them. I found the ...
1
vote
1answer
32 views

PATH preference in bashrc

I was wondering what happens in the following situation. Suppose I have an executable file in a directory that is in PATH in .bashrc. If I copy the file into another directory that is set in PATH ...
0
votes
1answer
17 views

How to fg a process suspended before starting tmux inside the new tmux session?

How to 1. suspend a process with ^Z, 2. start tmux and 3. fg (or bg) the suspended process? $ find / [.....] ^Z [1]+ Stopped sleep 10 $ tmux $ fg -bash: fg: current: no such job ...
1
vote
3answers
65 views

Is it possible to combine these two ssh commands into one?

I'm using bash on Mac 10.9.1. Right now, I execute these two commands to ultimately get to the server I want access to ssh me@intermediate and then once logged in, I execute ssh me@destination ...
1
vote
1answer
29 views

Run sed as a one-off ssh command

I would like to substitute a string with another in a file on a server of mine. I've tried doing this: ssh $REMOTE_HOST sed 's|export ${KEY}=${VAL}|export ${KEY}=${NEW_VAL}|' "$ENV_FILE" And a ...
2
votes
2answers
51 views

Using bash script to select/view only specific data from logfile

My NAS creates a logfile in the format below: <30>1 2014-07-21T05:02:10+02:00 ABC-NAS qlogd 6432 - - qlogd[6432]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, ...
-1
votes
1answer
37 views

How to run a random command every time I start a terminal

I have a doubt about script.I need to execute some random command when i open terminal its automatically execute that command. For Example, if i open first terminal the terminal will execute ls ...
10
votes
3answers
2k views

How can I add a command to the Bash history without executing it?

Every now and then it would be useful to add a command directly to the history in Bash without actually executing it. So far the closed thing I have found is adding a # in front of it and hitting ...
0
votes
0answers
15 views

Command 'at' does not work in one Synology NAS, though it works perfectly on another

I have installed at command on 2 different NAS synology. On 1, it works perfectly, on the other I get the message: Villars1> echo "touch /tmp/tt" | at now next minute warning: commands will be ...
8
votes
2answers
191 views

Cannot concatenate videos ffmpeg

I have a bitmap that I would like to concatenate to the front of many videos as a sort of title screen or disclaimer screen. I try to turn it into a video with the same attributes as the rest of the ...
0
votes
2answers
232 views

create file in directory without x permission set on directory : How?

From this page, http://content.hccfl.edu/pollock/aunix1/filepermissions.htm, I understand that I need the +w bit set in a directory to create a new file and +x bit to cd into it/access its inode. So ...
0
votes
1answer
34 views

What does if [-f file]; mean?

I have an if statement in a bash file: if [ -f bin/post_compile ]; then echo "-----> Running post-compile hook" chmod +x bin/post_compile sub-env bin/post_compile fi what does the -f ...
3
votes
3answers
50 views

Sed replace only in even numbered lines of a file when replace commands are written in a file

I have all the replace commands in a file (say replace.sed) and i use it with -f flag of sed (sed -f replace.sed InputFile). But now i ran into a condition where i need to apply these replace rules ...
0
votes
3answers
138 views

Get the last file name in a variable in bash?

In a directory, I have the following files: myfile_v01.txt myfile_v02.txt myfile_v03.txt How to make a bash script that detects the value of the last version and put the filename of this last ...
0
votes
0answers
45 views

Entered wrong .bash_profile and now my laptop is running hot

I am just learning how to use the command line and was editing the bash prompt setting in .bash_profile. I made an error in the prompt settings in .bash_profile and I lost the prompt and the ability ...
1
vote
1answer
76 views

How do I get `set show-all-if-ambiguous on` in my .inputrc to play nice with the Python interpreter?

I noticed that after I added the set show-all-if-ambiguous on line to my ~/.inputrc, whenever I pressed tab to indent a block, it would show me the bash Display all ... possibilities? (y or n) prompt, ...
0
votes
0answers
10 views

pidof Xorg is not returning a number on my computer

I'm trying to debug a performance problem with Xorg on my computer and I found a curious problem doing the operf command: pidof -sx Xorg, or just pidof Xorg outputs nothing. But ps -e | grep Xorg ...
3
votes
2answers
947 views

How to delete readonly variable in bash?

$ mySite="superuser" $ readonly mySite $ unset mySite bash: unset: mySite: cannot unset: readonly variable How can we delete mySite, as it is a readonly variable?
3
votes
5answers
444 views

Vim execute bash commands/make in the same window

When i try to run some commands like :make or :!ls , it shows the output in an altogether different screen/view and the file i am editing is not visible during this process. Is there anyway i can ...
2
votes
1answer
59 views

wc / cat command not found

I'm trying to run some simple bash script which uses wc and cat commands. The script fails with this: wc: command not found or this (after I commented string which uses wc): cat: command not found ...
2
votes
6answers
93 views

Compute md5sum of every 1MB part of stream from pipe

I want to do checksumming of large files and stream in unix/linux, and I want get many checksums from every large part of file/stream, every 1 MB or every 10MB. For example, I have disk image, ...
0
votes
1answer
28 views

grep: Invalid back reference for date expression in tcsh

I googled for the following error, and didn't get any great explanations as to what was going on with grep under tcsh. (Yes, that date expression exists in the log files). $ grep '2014-07-21' *.log ...
0
votes
2answers
66 views

PuTTY remote command containing while loop

I am attempting to automate several common tasks that I SSH into a remote server to do. For this, I am using PuTTY and its "remote command" option (Connection > SSH) in several saved sessions. My ...
0
votes
1answer
33 views

tar -czvf with no output file

Say you run tar -czvf some_folder_here and don't actually specify an output file, like tar -czvf some_output_file.tar some_folder_here. Where does the file go? I just ran this by accident, and the ...