Skip to content
Advertisement

Tag: unix

Bash: executing commands from within a chroot and switch user

Im writing a script that should do this… I have tried this approach: This tries to execute the user switching and the script as a string command to bash…however what it does, is it “stops” after “su -” and doesnt execute the script. However, once I leave the “su -” environment, it does try to run startup.sh but of course,

Why doesn’t “sort file1 > file1” work?

When I am trying to sort a file and save the sorted output in itself, like this the contents of the file1 is getting erased altogether, whereas when i am trying to do the same with ‘tee’ command like this it works fine [ed: “works fine” only for small files with lucky timing, will cause lost data on large ones

basename with spaces in a bash script?

I’m working on a bash script to create a new folder in /tmp/ using the name of a file, and then copy the file inside that folder. Behavior: When I type in mymove “/home/me/downloads/my new file.zip” it shows this: I have lots of quotes around everything, so I don’t understand why this is not working as expected. Also, I have

What does the brk() system call do?

According to Linux programmers manual: brk() and sbrk() change the location of the program break, which defines the end of the process’s data segment. What does the data segment mean over here? Is it just the data segment or data, BSS, and heap combined? According to wiki Data segment: Sometimes the data, BSS, and heap areas are collectively referred to

regular expression to exclude filetypes from find

When using find command in linux, one can add a -regex flag that uses emacs regualr expressions to match. I want find to look for all files except .jar files and .ear files. what would be the regular expression in this case? Thanks Answer You don’t need a regex here. You can use find with the -name and -not options:

How can I exclude directories from grep -R?

I want to traverse all subdirectories, except the “node_modules” directory. Answer SOLUTION 1 (combine find and grep) The purpose of this solution is not to deal with grep performance but to show a portable solution : should also work with busybox or GNU version older than 2.5. Use find, for excluding directories foo and bar : Then combine find and

bash scripting: how to find the absolute path of “symlink/..”?

Given two files: Upon calling parent/scripts/hello.sh from any location, I would like (in the script) to find the full path of the parent directory. In this case parent. The main issue is that parent/scripts/.. refers to generic in unix. On the other hand, everything involving regexes is not generic and may be error prone. Solutions that don’t work: All these

Tailing a file from where I left off before?

Suppose I have a file. I tail its last 10 lines and got some data. And the next time I come to tail, its length increases by 4. So I need to tail only that many lines to get data. Is there a simple command line for this? Like a mix of tail, wc, and grep? Answer If you save

Advertisement