Tag Info

New answers tagged

0

The only hard limit I'm aware of is PATH_MAX, you can check it (for current folder, value is filesystem dependent): getconf PATH_MAX . I would guess some of path elements were symlinks, and Your file was moved into "unexpected" folder. You should be able to find it by name or content. Try another shell (tcsh, sh, ... ) as there may be some shell ...


0

Define the custom prompt of root in his .bash_profile, not in your regular user's profile. Usually this is the default setup anyway, without manually having to edit it. Note that when you use su without arguments, it doesn't read root's rc files, that's why the prompt doesn't change. To make su read root's rc files, use su - (with a dash as parameter). That ...


0

I think what You need is: find /data/oozie-admi/ -mindepth 1 -type d -ctime +1 | xargs rm -rf or: find /data/oozie-admi/ -mindepth 1 -type d -ctime +1 -exec rm -rf + Both commands should work the same (on Linux), second one a bit more realiable for big number of folders.


0

Yes, your multiple terminals is the reason. The bash history is written when you exit the shell, not individually for each command. You can get your history file in chronological order with sort: history | sort -k2 If your want your history file to be written more continoulsy, I believe this blog post explains it quite well I also found this unix stack ...


1

This page on U&L gives a good description of what ctime does in the find command: According to the find man page, -ctime n File's status was last changed n*24 hours ago. +n for greater than n Therefore -ctime +1 means the file status must have changed at least 48 hours ago. The -type d would specify to only return directories. So find ...


2

Until asteri clarified the question, I thought John1024 had the answer. Now it seems that the following will work without the --color option: ls -d $(ls | head -30) Unfortunately this is too simplistic and will fail if there are blanks in the file names. To take account of that you need the more elaborate: ls -b | head -30 | xargs ls -d In both cases ...


2

To get coloring: ls -l --color=always | head -30 Normally, ls produces color only when the output is going directly to a terminal. This is generally a good thing. To override that, use --color=always The above produces output with one file per line. If you want, space allowing, more files per line, then try: ls -l | head -30 | column The column ...


0

If you use convert instead of mogrify (part of the same suite), your command then becomes: find . -iname '*.jpg' -exec convert -format pdf '{}' new/'{}'.pdf \; Unlike mogrify, convert uses does not create an updated file extension, so you will get .jpg.pdf (plus capitalisation) as the new file extension, but that is easy to change with rename: find new ...


0

I'm not sure what would be causing the difference in the two runs, but I have some ideas for consistency and speed which may help. First, here are the differences in operations between root and non-root scans with the options you selected: Unprivileged (non-root) scans will use a pair of TCP connect() calls to determine if the host is up; root scans will ...


0

find . -iname '*.jpg' | while read f ; do new=`echo $f | sed -e 's/\.[Jj][Pp][Gg]$/.pdf/'`; newd=`dirname $f`; newd="new/$newd" mogrify -format pdf $f; mv $new $newd; done Of course, I recommend running the script echoing the mogrify and mv commands. If mogrify offers an output option, use that instead of the mv. You may find it ...


0

After further research, I found something of interest in the MISC section of the man page. There is a option for --unprivileged which forces operation as a normal user, even as root. This performs significantly less operations and provides less info back, but if all you are doing is checking for ssh on port 22, it does it as fast as possible.


0

You should use absolute paths, instead of relative ones, uniformly through your one-liner. It should be: find /path/to/starting/directory -name '20*.log' -ctime +90 -exec 'tar zvcf {}.tgz {}*' \;


2

Solution By supplying the option -c (or --total) to du(1), you can instruct it to produce a grand total. If your implementation of du(1) supports either of these options, you can achieve the desired effect using the following statement: $ find . -name 'flibble*' -ctime +90 -exec du -shc {} + Explanation The difference between the semantics of -exec ...


0

Try once removing quotes around the tar command and also remove * after { }, why you are using * after { }. I have checked it it is working fine.


0

Why do you have quotes around your tar command? Kill the quotes. You're trying to run the command: tar zvcf /var/log/fwlogzip/./2014111test.log.tgz ./2014111test.log* with no arguments Remember that UNIX commands can have embedded spaces in it. I can't test this but: find . -name '20*.log' -ctime +90 -exec tar zvcf /var/log/logzip/{}.tgz {}* \; ...


3

Try this: du -c `find . -name 'flibble*' -ctime +90` | tail -1 The original command is giving du one argument, then executing it, until it goes through all the arguments. This way, you simply are giving it all the arguments at once, then cutting off the separate sizes, and leaving only the total. You can remove the pipe and tail to show the size of each ...


1

I would have find itself print out the size, and use another tool to calculate the total: find . -name 'flibble*' -ctime +90 -printf "%s\n" | perl -lnE '$sum += $_} END {say $sum' If you also want to see the filenames: find . -name 'flibble*' -ctime +90 -printf "%s\t%p\n" | perl -apE '$sum += $F[0]} END {say $sum'


0

As navigation through history using Ctrl-r is IMO cumbersome, you may want to consider hh: https://github.com/dvorka/hstr which makes navigation much simpler, straightforward and efficient - including running the command:


1

It seems you are that user -- why not echo $HOME ?


0

Assuming that all your lines have the same format for URL, you could get the timestamp and number string with a sed command like this one: $ sed -r 's|.*\[(.*)\].*=%(.*)&sub.*|\1 \2|g' /var/log/httpd/access_log 16/Dec/2014:06:27:30 +0100 2B2341231231234 That expression takes whatever exist inside [ and ] (should be the timestamp) and whatever exists ...


0

Nevermind, found out that it was Windows adding invalid characters. With Notepad++, saving as Unix/Linux worked like a charm.


1

(answering for bash) No. The shell processes redirections first, which then truncates the file. Only then does cat start, and it's operating with an empty file. There is a tool called sponge in the moreutils package that lets you do this: cat somefile.txt | sort | uniq | sponge somefile.txt This command can be simplified (remove UUOC): sort -u ...


3

That's caused by the ignorespace value in $HISTCONTROL. From man bash: HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. It could be caused by the HISTIGNORE ...


3

Here is a one-liner: find -mindepth 3 -maxdepth 3 -type d | while read -r name; do mv -v "$name" "${name/????-??-}"; done to be executed in basedir. The line break is just for readability but technically it is a one-liner. I highly recommend to create a backup before executing. This command does no sanity checks. It is not at all safe to execute on ...


2

This is how I setup a task for doing SSh with cygwin: Simply add this to the command section for a task. Create a task for each connection and change the -new_console:t: bit set CHERE_INVOKING=1 & %SystemDrive%\CygWin\bin\sh.exe -exec "ssh user@10.0.0.11" -new_console:t:Server -new_console:t:Server == A new console tab with the name Server An ...


0

This should work. It uses stat to extract the username of the owner of the pseudo-tty. Here, $pts should be in the format in the question, eg. pts/2. tty_user=$(stat -c%U /dev/$pts)


2

Normally, sed processes each line (doing substitutions etc), then prints the result. If the processing involves the line being printed (e.g. sed's p command), then it gets printed twice (once during processing, then again by the automatic post-processing print). The -n option disables the automatic printing, which means the lines you don't specifically tell ...


0

The key key difference between those two command sequences is that the second contains echo $b which performs shell word splitting. To make the second command sequence run the same as the first, replace: echo $b | grep "*)>nS4XkrlH @XUL" with: echo "$b" | grep "*)>nS4XkrlH @XUL" Word Splitting Observe how spaces are treated in these two echo ...


1

Short answer: See BashFAQ #50: I'm trying to put a command in a variable, but the complex cases always fail!. Long answer: When the shell parses a command line, it does it does things like figuring out which portions of the line are in quotes (or escaped or whatever) before it substitutes variables; thus, if you have any quotes or escapes inside the ...


3

vim is the sucessor to vi. It stands for vi improved. /usr/bin/vi is just a symlink to vim. You can see this with: ls -l /usr/bin/vi To start "classic vi": vim -u NONE myText.txt How it works: vim looks for a config file at ~/.vimrc, if this is found it will run as vim unless the line set compatibility appears in .vimrc. To save editing the .vimrc ...


4

Because Vim is a well-maintained, vi-compatible, Open Source editor, so it is a perfect match for Linux. I've last seen implementations of pure "vi" on proprietary Unixes like SunOS, HP-UX, AIX; you might get "lucky" on BSD, too. (But of course Vim can be installed on those, too.) On Ubuntu, what gets installed by default is a stripped-down version of Vim ...


1

Type first letters of the command and press F8. Alternatively you can press F7 and type first letters. More details: http://technet.microsoft.com/en-us/magazine/ff678293.aspx


0

I ran into this problem myself recently, but in my case I couldn't separate my code into two separate functions, nor could I predict the name of the global variable I was going to set. The following is what I came up with. The calling syntax is different, but easy enough. It may require some fiddling with backslash escapes, however. Basically, it works ...


0

Specify bash instead of sh when running the script. I personally noticed they are different under ubuntu 12.10: bash script.sh arg0 ... argn


0

The idiom I've used is this: cmd="some command in a string" "$cmd" Note that unlike using exec, the calling script will continue. Some modification may be required if your command includes special characters. Here's another variation I've used (I don't remember why I did it this way): cmd="some command in a string" bash -c "$cmd" Here's a complete ...


0

As you have typed it COMMAND-TO-EXECUTE is not a valid shell variable name, remove the dashes. This might give some clues: $ echo $COMMAND-TO-EXECUTE -TO-EXECUTE $ COMMAND-TO-EXECUTE=Test COMMAND-TO-EXECUTE=Test: command not found $ COMMAND_TO_EXECUTE=Test $ echo $COMMAND_TO_EXECUTE Test $ Then "foo "$1" --option1 --option2 "$2 looks a bit odd. If ...


1

You could use tr -d: $ xclip -o | tr -d "-" | xclip


0

I don't understand what you expect "expect" to be: $ type -a expect bash: type: expect: not found Here a simple example that might give clues: $ bash -c 'echo "Hi, I am alive." ; read -p "Press ENTER to exit> " ans ; echo "You typed $ans"' Hi, I am alive. Press ENTER to exit> exit You typed exit man bash, help read and the Bash guides at ...


0

There are several ways to counteract loss of connectivity for ssh sessions. First, you may wish to set the options ServerAliveInterval, ClientAliveInterval and ClientAliveCountMax. ServerAliveInterval is the number of seconds that the client will wait before sending a null packet to the server (to keep the connection alive), a value of 60 is typical. ...


0

Using awk: awk 'END{print}' RS='---' file RS defines --- as record separator and with END{print} we only prints the last record. Using sed: sed -r ':a;$!{N;ba};s:^(.*\n?)---::' file


1

Alright, it took me some time to understand what tar -F actually does (is that documented anywhere at all? I just ended up reading the source), but I think I came up with a pretty good solution for you. Since pv doesn't support pretending that a certain progress has already been made, I needed to replace it with a similar tool called bar (available in ...


0

Using %h instead %p has already been suggested in another answer, but I'd like to add some improvements to make your code more robust. If, for instance, a matching directory contains a newline character in its name, you will in the best-case end up missing directories and getting some error messages from cp. At worst, you might override files anywhere on ...


1

The following works in Unbuntu: echo -e value1\\nvalue2|echo mkdir -p ./`line`/`line` I can't guarantee that all bash implementations will read the lines in left-to-right order. Alternatively: echo value1 value2|( read p1 p2; echo mkdir -p ./$p1/$p2 ) This will work with all bash implementations, but will need elaboration if either value contains ...


1

How about echo v1 v2 | awk '{print "./"$1"/"$2}' | xargs mkdir -p


1

Given a variation on pathmunge in /etc/profile munge () { if [[ ":${!1}:" != *:"$2":* ]]; then if [[ $3 == after ]]; then declare -g $1="${!1}:$2" else declare -g $1="$2:${!1}" fi fi } We can do: $ A=a $ munge A b after $ echo $A a:b $ munge A c before $ echo $A c:a:b $ munge A a before $ echo $A ...


1

I was having this same problem since I began using "Environment Modules". The solution (for me at least) was to update bash I had been using bash 4.1.2-15.el6 and updated to bash 4.1.2-29.el6 with: yum update bash Obviously you may not be able to convince "mega corp" to update but given the concern around shellshock they might listen to you?


1

According to this article, http://www.linuxjournal.com/content/return-values-bash-functions, it is possible to modify an outside variable, given its name, like this: function myfunc() { local __resultvar=$1 local myresult='some value' eval $__resultvar="'$myresult'" } myfunc result echo $result Now, using this script and the original ...


0

First option - check that C:\cygwin\bin\sh.exe is in the PATH (if not, set the sh location in the system config), all you need to do is to just enter the shell script in the "execute shell script" box of the job configuration. If it won't work, try this: The default cygwin.bat file opens a shell without passing any parameters to it. You could make a copy ...


0

I just met a similar problem. After reading the watch Man Page, I found a solution that could work, which is to concatenate strings in bash. The final command looked weird, such as: watch "ps -ef | awk -F' ' '"'{print $2}'"'" or watch 'ps -ef | awk -F'"' ' '"'{print $2}'"'"


0

I think you are almost there. You can replace %p with %h in the -printf expression : %h : Leading directories of file's name (all but the last element). If the file name contains no slashes (since it is in the current directory) the %h specifier expands to ".". so the command would be something like : find "$dir" -name Sample.doc -printf "%h\n" | ...



Top 50 recent answers are included