date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,294,624,203,000
When I execute a program without specifying the full path to the executable, and Bash must search the directories in $PATH to find the binary, it seems that Bash remembers the path in some sort of cache. For example, I installed a build of Subversion from source to /usr/local, then typed svnsync help at the Bash promp...
bash does cache the full path to a command. You can verify that the command you are trying to execute is hashed with the type command: $ type svnsync svnsync is hashed (/usr/local/bin/svnsync) To clear the entire cache: $ hash -r Or just one entry: $ hash -d svnsync For additional information, consult help hash an...
How do I clear Bash's cache of paths to executables?
1,294,624,203,000
I understand how to define include shared objects at linking/compile time. However, I still wonder how do executables look for the shared object (*.so libraries) at execution time. For instance, my app a.out calls functions defined in the lib.so library. After compiling, I move lib.so to a new directory in my $HOME. H...
The shared library HOWTO explains most of the mechanisms involved, and the dynamic loader manual goes into more detail. Each unix variant has its own way, but most use the same executable format (ELF) and have similar dynamic linkers¹ (derived from Solaris). Below I'll summarize the common behavior with a focus on Lin...
Where do executables look for shared objects at runtime?
1,294,624,203,000
I have an executable for the perforce version control client (p4). I can't place it in /opt/local because I don't have root privileges. Is there a standard location where it needs to be placed under $HOME? Does the File System Hierarchy have a convention that says that local executables/binaries need to be placed in $...
In general, if a non-system installed and maintained binary needs to be accessible system-wide to multiple users, it should be placed by an administrator into /usr/local/bin. There is a complete hierarchy under /usr/local that is generally used for locally compiled and installed software packages. If you are the only ...
Where should a local user executable be placed (under $HOME)?
1,294,624,203,000
I'm learning C#, so I made a little C# program that says Hello, World!, then compiled it with mono-csc and ran it with mono: $ mono-csc Hello.cs $ mono Hello.exe Hello, World! I noticed that when I hit TAB in bash, Hello.exe was marked executable. Indeed, it runs by just a shell loading the filename! Hello.exe is no...
This is binfmt_misc in action: it allows the kernel to be told how to run binaries it doesn't know about. Look at the contents of /proc/sys/fs/binfmt_misc; among the files you see there, one should explain how to run Mono binaries: enabled interpreter /usr/lib/binfmt-support/run-detectors flags: offset 0 magic 4d5a (...
How is Mono magical?
1,294,624,203,000
Before today, I've used the terminal to a limited extent of moving in and out of directories and changing the dates of files using the touch command. I had realised the full extent of the terminal after installing a fun script on Mac and having to chmod 755 the file to make it executable afterwards. I'd like to know w...
/usr/local/bin is for programs that a normal user may run. The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts,...
What is /usr/local/bin?
1,294,624,203,000
I am trying to understanding the concept of special files on Linux. However, having a special file in /dev seems plain silly when its function could be implemented by a handful of lines in C to my knowledge. Moreover you could use it in pretty much the same manner, i.e. piping into null instead of redirecting into /de...
In addition to the performance benefits of using a character-special device, the primary benefit is modularity. /dev/null may be used in almost any context where a file is expected, not just in shell pipelines. Consider programs that accept files as command-line parameters. # We don't care about log output. $ frobify ...
Why is /dev/null a file? Why isn't its function implemented as a simple program?
1,294,624,203,000
Why do we use ./filename to execute a file in linux? Why not just enter it like other commands gcc, ls etc...
In Linux, UNIX and related operating systems, . denotes the current directory. Since you want to run a file in your current directory and that directory is not in your $PATH, you need the ./ bit to tell the shell where the executable is. So, ./foo means run the executable called foo that is in this directory. You can ...
Why do we use "./" (dot slash) to execute a file in Linux/UNIX?
1,294,624,203,000
This may be a silly question, but I ask it still. If I have declared a shebang #!/bin/bash in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash [my@comp]$bash my_shell_script.sh or can I use e.g. [my@comp]$sh my_shell_script.sh and my script determines the running shell usin...
The shebang #! is an human readable instance of a magic number consisting of the byte string 0x23 0x21, which is used by the exec() family of functions to determine whether the file to be executed is a script or a binary. When the shebang is present, exec() will run the executable specified after the shebang instead. ...
Does the shebang determine the shell which runs the script?
1,294,624,203,000
I've created a bash script but when I try to execute it, I get #!/bin/bash no such file or directory I need to run the command: bash script.sh for it to work. How can I fix this?
This kind of message is usually due to a buggy shebang line, either an extra carriage return at the end of the first line or a BOM at the beginning of it. Run: $ head -1 yourscript | od -c and see how it ends. This is wrong: 0000000 # ! / b i n / b a s h \r \n This is wrong too: 0000000 357 2...
#!/bin/bash - no such file or directory
1,294,624,203,000
If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
The kernel interprets the line starting with #! and uses it to run the script, passing in the script's name; so this ends up running /bin/rm scriptname which deletes the script. (As Stéphane Chazelas points out, scriptname here is sufficient to find the script — if you specified a relative or absolute path, that's pa...
Why does the following script delete itself?
1,294,624,203,000
I made a backup to an NTFS drive, and well, this backup really proved necessary. However, the NTFS drive messed up permissions. I'd like to restore them to normal w/o manually fixing each and every file. One problem is that suddenly all my text files gained execute permissions, which is wrong ofc. So I tried: sudo chm...
If you are fine with setting the execute permissions for everyone on all folders: chmod -R -x+X -- 'folder with restored backup' The -x removes execute permissions for all The +X will add execute permissions for all, but only for directories. See Stéphane Chazelas's answer for a solution that uses find to really not ...
How to recursively remove execute permissions from files without touching folders?
1,294,624,203,000
Is it possible to execute a script if there is no permission to read it? In root mode, I made a script and I want the other user to execute this script but not read it. I did chmod to forbid read and write but allow execute, however in user mode, I saw the message that says: permission denied.
The issue is that the script is not what is running, but the interpreter (bash, perl, python, etc.). And the interpreter needs to read the script. This is different from a "regular" program, like ls, in that the program is loaded directly into the kernel, as the interpreter would. Since the kernel itself is reading...
Can a script be executable but not readable?
1,294,624,203,000
I've got a simple script: #!/usr/bin/env ruby --verbose # script.rb puts "hi" On my OSX box, it runs fine: osx% ./script.rb hi However, on my linux box, it throws an error linux% ./script.rb /usr/bin/env: ruby --verbose: No such file or directory If I run the shebang line manually, it works fine linux% /usr/bin/env...
Looks like this is because Linux (unlike BSD) only passes a single argument to the shebang command (in this case env). This has been extensively discussed on StackOverflow.
Shebang line with `#!/usr/bin/env command --argument` fails on Linux
1,294,624,203,000
I have currently a strange problem on debian (wheezy/amd64). I have created a chroot to install a server (i can't give any more detail about it, sorry). Let's call its path /chr_path/. To make things easy, I have initialized this chroot with a debootstrap (also wheezy/amd64). All seemed to work well inside the chroot ...
When you fail to execute a file that depends on a “loader”, the error you get may refer to the loader rather than the file you're executing. The loader of a dynamically-linked native executable is the part of the system that's responsible for loading dynamic libraries. It's something like /lib/ld.so or /lib/ld-linux....
Getting "Not found" message when running a 32-bit binary on a 64-bit system
1,294,624,203,000
On 32-bit Linux systems, invoking this $ /lib/libc.so.6 and on 64-bit systems this $ /lib/x86_64-linux-gnu/libc.so.6 in a shell, provides an output like this: GNU C Library stable release version 2.10.1, by Roland McGrath et al. Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source ...
That library has a main() function or equivalent entry point, and was compiled in such a way that it is useful both as an executable and as a shared object. Here's one suggestion about how to do this, although it does not work for me. Here's another in an answer to a similar question on S.O, which I'll shamelessly p...
Why and how are some shared libraries runnable, as though they are executables?
1,294,624,203,000
With Bash's source it is possible to execute a script without an execution bit set. This is documented and expected behaviour, but isn't this against the use of an execution bit? I know, that source doesn't create a subshell.
Bash is an interpreter; it accepts input and does whatever it wants to. It doesn't need to heed the executable bit. In fact, Bash is portable, and can run on operating systems and filesystems that don't have any concept of an executable bit. What does care about the executable bit is the operating system kernel. Wh...
Why does Bash's source not need the execution bit?
1,294,624,203,000
What are the different methods to run a non-nixos executable on NixOs? (For instance proprietary binaries.) I'd like to see also the manual methods.
Related answers If you plan to package a binary and not just run it, you might like this other answer of mine: How to package my software in nix or write my own package derivation for nixpkgs Short version Quick and dirty: make sure steam-run is installed (strange name, it has nothing to do with steam), e.g. nix-shell...
Different methods to run a non-nixos executable on Nixos
1,294,624,203,000
Is there a one-liner that will list all executables from $PATH in Bash?
This is not an answer, but it's showing binary, a command which you could run compgen -c (assuming bash) Other useful commands compgen -a # will list all the aliases you could run. compgen -b # will list all the built-ins you could run. compgen -k # will list all the keywords you could run. compgen -A function # wil...
List all binaries from $PATH
1,294,624,203,000
I recently learned that (at least on Fedora and Red Hat Enterprise Linux), executable programs that are compiled as Position Independent Executables (PIE) receive stronger address space randomization (ASLR) protection. So: How do I test whether a particular executable was compiled as a Position Independent Executable,...
You can use the perl script contained in the hardening-check package, available in Fedora and Debian (as hardening-includes). Read this Debian wiki page for details on what compile flags are checked. It's Debian specific, but the theory applies to Red Hat as well. Example: $ hardening-check $(which sshd) /usr/sbin/ssh...
How to test whether a Linux binary was compiled as position independent code?
1,294,624,203,000
From man file, EXAMPLES $ file file.c file /dev/{wd0a,hda} file.c: C program text file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped /dev/wd0a: block special (0/0) /dev/hda: block special (3/0) $ file -s /dev/wd0{b,d} ...
If you compile an executable with gcc's -g flag, it contains debugging information. That means for each instruction there is information which line of the source code generated it, the name of the variables in the source code is retained and can be associated to the matching memory at runtime etc. Strip can remove thi...
What are stripped and not-stripped executables in Unix?
1,294,624,203,000
I have a Python script that need to be run with a particular python installation. Is there a way to craft a shebang so that it runs with $FOO/bar/MyCustomPython?
The shebang line is very limited. Under many unix variants (including Linux), you can have only two words: a command and a single argument. There is also often a length limitation. The general solution is to write a small shell wrapper. Name the Python script foo.py, and put the shell script next to foo.py and call it...
How can I use environment variables in my shebang?
1,294,624,203,000
I'm wondering about the way Linux manages shared libraries. (actually I'm talking about Maemo Fremantle, a Debian-based distro released in 2009 running on 256MB RAM). Let's assume we have two executables linking to libQtCore.so.4 and using its symbols (using its classes and functions). For simplicity's sake let's call...
NOTE: I'm going to assume that your machine has a memory mapping unit (MMU). There is a Linux version (µClinux) that doesn't require an MMU, and this answer doesn't apply there. What is an MMU? It's hardware—part of the processor and/or memory controller. Understanding shared library linking doesn't require you to und...
Loading of shared libraries and RAM usage
1,294,624,203,000
There are several ways to execute a script. The ones I know are: /path/to/script # using the path (absolute or relative) . script # using the . (dot) source script # using the `source` command Are there any other way? What are the differences between them? Are there situations that I must use one and not ano...
Another way is by calling the interpreter and passing the path to the script to it: /bin/sh /path/to/script The dot and source are equivalent. (EDIT: no, they're not: as KeithB points out in a comment on another answer, "." only works in bash related shells, where "source" works in both bash and csh related shells.) ...
Different ways to execute a shell script
1,294,624,203,000
Why does sshd require an absolute path when restarting, e.g /usr/sbin/sshd rather than sshd Are there any security implications? P.S the error message: # sshd sshd re-exec requires execution with an absolute path
This is specific to OpenSSH from version 3.9 onwards. For every new connection, sshd will re-execute itself, to ensure that all execute-time randomisations are re-generated for each new connection. In order for sshd to re-execute itself, it needs to know the full path to itself. Here's a quote from the release notes ...
Why does sshd requires an absolute path?
1,294,624,203,000
I know there are many differences between OSX and Linux, but what makes them so totally different, that makes them fundamentally incompatible?
The whole ABI is different, not just the binary format (Mach-O versus ELF) as sepp2k mentioned. For example, while both Linux and Darwin/XNU (the kernel of OS X) use sc on PowerPC and int 0x80/sysenter/syscall on x86 for syscall entry, there's not much more in common from there on. Darwin directs negative syscall numb...
What makes OSX programs not runnable on Linux?
1,294,624,203,000
And now I am unable to chmod it back.. or use any of my other system programs. Luckily this is on a VM I've been toying with, but is there any way to resolve this? The system is Ubuntu Server 12.10. I have attempted to restart into recovery mode, unfortunately now I am unable to boot into the system at all due to per...
Boot another clean OS, mount the file system and fix permissions. As your broken file system lives in a VM, you should have your host system available and working. Mount your broken file system there and fix it. In case of QEMU/KVM you can for example mount the file system using nbd.
How to recover from a chmod -R 000 /bin?
1,294,624,203,000
I'm stumped. I have a script in my /home directory which is executable: [user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh However, when I attempt to run it with sudo it says it can't find it: [user@server ~]$ sudo ./qa.sh [sudo] password for user: sudo: unable to execute ./qa.sh: No such fi...
This usually happens when the shebang (#!) line in your script is broken. The shebang is what tells the kernel the file needs to be executed using an interpreter. When run without sudo, the message is a little more meaningful. But with sudo you get the message you got. For example: $ cat test.sh #!/bin/foo echo bar $...
sudo: unable to execute ./script.sh: no such file or directory
1,294,624,203,000
The example I have is Minecraft. When running Bukkit on Linux I can remove or update the .jar files in the /plugins folder and simply run the 'reload' command. In Windows, I have to take the whole server process down because it will complain that the .jar file is currently in use when I try to remove or replace it. ...
Linux deletes a file completely differently than the way Windows does. First, a brief explanation on how files are managed in the *unix native file systems. The file is kept on the disk in the multilevel structure called i-node. Each i-node has an unique number on the single filesystem. The i-node structure keeps diff...
What is Linux doing differently that allows me to remove/replace files where Windows would complain the file is currently in use?
1,294,624,203,000
We have two systems with similar hardware (main point being the processor, let us say a standard intel core 2 duo). One is running (insert your linux distro here: Ubuntu will be used henceforth), and the other is running let's say Mac OS X. One compiles an equivalent program, Let us say something like: int main() { ...
You forget one crucial thing, namely that your program will have to interact with the operating system to do anything interesting. The conventions are different between Linux and OS X so the same binary cannot run as-is without essentially having a chunk of operating system dependent code to be able to interact with i...
Binary compatibility between Mac OS X and Linux
1,294,624,203,000
I want to launch the wine executable (Version 2.12), but I get the following error ($=shell prompt): $ wine bash: /usr/bin/wine: No such file or directory $ /usr/bin/wine bash: /usr/bin/wine: No such file or directory $ cd /usr/bin $ ./wine bash: ./wine: No such file or directory However, the file is there: $ which w...
This: $ file /usr/bin/wine /usr/bin/wine: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=eaf6de433d8196e746c95d352e0258fe2b65ae24, stripped Combined with this: $ ldd /usr/bin/wine /usr/bin/ldd: line 117: /usr/bin/wine...
Linux executable fails with "File not found" even though the file is there and in PATH
1,294,624,203,000
For example: $ node -bash: /usr/local/bin/node: No such file or directory $ foo -bash: foo: command not found What's the difference? In both cases, node and foo are invalid commands, but it seems like Unix just can't find the node binary? When uninstalling a program, e.g. node, is there a way to clean this up so that...
That's because bash remembered your command location, store it in a hash table. After you uninstalled node, the hash table isn't cleared, bash still thinks node is at /usr/local/bin/node, skipping the PATH lookup, and calling /usr/local/bin/node directly, using execve(). Since when node isn't there anymore, execve() r...
Difference between "command not found" and "no such file or directory"?
1,294,624,203,000
I'm writing a program that will test programs written by students. I'm afraid that I can't trust them and I need to make sure that it won't end up badly for the computer running it. I was thinking about making some crash test user with limited access to system resources and run programs as that user, but from what I ...
Virtual machine can give you highest security without reboot, but lowest performance. Another option, for even higher security than a virtual machine: boot a "live" CD/DVD/pendrive without access to the hard drive (temporarily disable the HDD in BIOS; if you can't, at least do not mount the drive / unmount it, if mou...
Execution of possibly harmful program on Linux
1,294,624,203,000
I have found the term "LSB executable" or "LSB shared object" in the output of the file command in Linux. For example: $ file /bin/ls /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=4637713da6cd9aa30d1528471c...
“LSB” here stands for “least-significant byte” (first), as opposed to “MSB”, “most-significant byte”. It means that the binary is little-endian. file determines this from the sixth byte of the ELF header.
What does "LSB" mean when referring to executable files in the output of /bin/file?
1,294,624,203,000
How can I execute a command making it believe that is on a different date than system one? For instance, if I have this script: #!/usr/bin/env bash date +"%B %d, %Y" It prints the actual date: march 13, 2014 But I would like it to print a different date, on the future or past, without changing the system date. I...
Using the libfaketime software could be a solution sudo apt-get install faketime faketime '2006-09-20' wine Example.exe
How to trick a particular command into thinking it is a different date?
1,294,624,203,000
I installed Debian in VirtualBox (for various experiments which usually broke my system) and tried to launch the VirtualBox guest addon script. I logged in as root and tried to launch autorun.sh, but I got «Permission denied». ls -l shows that the script have an executable rights. Sorry, that I can't copy the output -...
Maybe your file system is mounted with noexec option set, so you can not run any executable files. From mount documentation: noexec Do not allow direct execution of any binaries on the mounted filesystem. (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This tri...
Running sh script: «Permission denied» despite the executable bit and root rights
1,294,624,203,000
I am programming a Linux shell script that will print status banners during its execution only if the proper tool, say figlet, is installed (this is: reachable on system path). Example: #!/usr/bin/env bash echo "foo" figlet "Starting" echo "moo" figlet "Working" echo "foo moo" figlet "Finished" I would like for my ...
My interpretation would use a wrapper function named the same as the tool; in that function, execute the real tool if it exists: figlet() { if command -p figlet >/dev/null 2>&1 then command figlet "$@" else : fi } Then you can have figlet arg1 arg2... unchanged in your script. @Olorin came...
Linux shell script: Run a program only if it exists, ignore it if it does not exist
1,294,624,203,000
root user can write to a file even if its write permissions are not set. root user can read a file even if its read permissions are not set. root user can cd into a directory even if its execute permissions are not set. root user cannot execute a file when its execute permissions are not set. Why? user$ echo '#!'$(whi...
In short, because the execute bit is considered special; if it's not set at all, then the file is considered to be not an executable and thus can't be executed. However, if even ONE of the execute bits is set, root can and will execute it. Observe: caleburn: ~/ >cat hello.sh #!/bin/sh echo "Hello!" caleburn: ~/ >chm...
Why can't root execute when executable bits are not set?
1,294,624,203,000
Supposing I am in the same folder as an executable file, I would need to type this to execute it: ./file I would rather not have to type /, because / is difficult for me to type. Is there an easier way to execute a file? Ideally just some simple syntax like: .file or something else but easier than having to insert t...
It can be "risky" but you could just have . in your PATH. As has been said in others, this can be dangerous so always ensure . is at the end of the PATH rather than the beginning.
Execute as .test rather than ./test
1,347,119,015,000
It's years I use Linux systems on a daily basis, and I never had major problems by updating a system when it was running, but I still wonder why this is possibile. Let me make an example. Suppose a program "A" from a certain package is running on a system. This program, at a certain point, needs to open another file (...
Updating Userland is Rarely a Problem You can often update packages on a live system because: Shared libraries are stored in memory, not read from disk on each call, so the old versions will remain in use until the application is restarted. Open files are actually read from file-descriptors, not the file names, so th...
Why updating a running Linux system is not problematic?
1,347,119,015,000
I understand that Linux uses shebang line to determine what interpreter to use for scripting languages, but how does it work for binaries? I mean I can run Linux binaries, and having installed both wine and mono, Windows native and .NET binaries. And for all of them it's just ./binary-name (if not in PATH) to run it. ...
In a word: binfmt_misc. It's a Linux-specific, non-portable, facility. There are a couple of formats that are recognized by the kernel with built-in logic. Namely, these are the ELF format (for normal binaries) and the shebang convention (for scripts). (thanks to zwol for the following part of the answer). In addition...
How does Linux determine what facilities to use to run a (non-text) binary?
1,347,119,015,000
I was reading up on chmod and its octal modes. I saw that 1 is execute only. What is a valid use case for an execute only permission? To execute a file, one typically would want read and execute permission. $ echo 'echo foo' > say_foo $ chmod 100 ./say_foo $ ./say_foo bash: ./say_foo: Permission denied $ chmod 500 ...
Shell scripts require the read permission to be executed, but binary files do not: $ cat hello.cpp #include<iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; } $ g++ -o hello hello.cpp $ chmod 100 hello $ ./hello Hello, world! $ file hello hello: executable, regular file, no read per...
What is a valid use case for an "execute only" file permission?
1,347,119,015,000
I have some doubts regarding *nix. I don't know which type of executable file is ls, whether it is .sh or .ksh or any other kind of system executable if it is, what is that? when I tried to see what is the source code of ls command looks like, it shows something unreadable, what method does *nix use to create these ...
You can determine the nature of an executable in Unix using the file command and the type command. type You use type to determine an executable's location on disk like so: $ type -a ls ls is /usr/bin/ls ls is /bin/ls So I now know that ls is located here on my system in 2 locations:/usr/bin/ls & /bin/ls. Looking at t...
How are system commands like ls created?
1,347,119,015,000
Is there any way to set +x bit on script while creating? For example I run: vim -some_option_to_make_file_executable script.sh and after saving I can run file without any additional movings. ps. I can run chmod from vim or even from console itself, but this is a little annoying, cause vim suggests to reload file. Als...
I don't recall where I found this, but I use the following in my ~/.vimrc " Set scripts to be executable from the shell au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif The command automatically sets the executable bit if the first line starts with "#!" or...
vim: create file with +x bit
1,347,119,015,000
Whenever I run file on an ELF binary I get this output: [jonescb@localhost ~]$ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped I'm just wondering what changed in Linux 2.6.9 that this binary coul...
glibc has a configure option called --enable-kernel that lets you specify the minimum supported kernel version. When object files are linked with that glibc build, the linker adds a SHT_NOTE section to the resulting executable named .note.ABI-tag that includes that minimum kernel version. The exact format is defined i...
Why does the file command say that ELF binaries are for Linux 2.6.9?
1,347,119,015,000
How can I set file to be executable only to other users but not readable/writable, the reason for this I'm executing something with my username but I don't want to give out the password. I tried : chmod 777 testfile chmod a=x chmod ugo+x I still get permission denied when executing as another user.
You need both read and execute permissions on a script to be able to execute it. If you can't read the contents of the script, you aren't able to execute it either. tony@matrix:~$ ./hello.world hello world tony@matrix:~$ ls -l hello.world -rwxr-xr-x 1 tony tony 17 Jul 13 22:22 hello.world tony@matrix:~$ chmod 100 hel...
File permission execute only
1,347,119,015,000
I'm confused about execute file permissions not behaving as I expect. Probably because my expectations are wrong. Anyway: I have a script file, for simplicity is just called s, located in ~/bin. For the sake of this example, the file contains just the following lines: #!/bin/zsh echo "Test"; Very simple. I navigate ...
When you run ./s, you tell the kernel to execute the program s. If you have execution permission, then the kernel reads the first few bytes of the file, sees the #! line so it knows that this is a script, and runs the interpreter, passing it the script name as its first argument. If you don't have execute permission, ...
Executing a script in zsh - file permissions
1,347,119,015,000
I sometimes run into software that is not offered in .deb or .rpm but only as an executable. For example Visual Studio Code, WebStorm or Kerbal Space Programm. For this question, I will take Visual Studio Code as the point of reference. The software is offered as a zipped package. When unzipping, I'm left with a fol...
To call a program by its name, shells search the directories in the $PATH environment variable. In Debian, the default $PATH for your user should include /home/YOUR-USER-NAME/bin (i.e. ~/bin). First make sure the directory ~/bin exists or create it if it does not: mkdir -p ~/bin You can symlink binaries to that direc...
How to install executables
1,347,119,015,000
echo 'main(){}' | gcc -xc - -o /dev/stdout | ??? Is there a way to run the output binary on a unix-like system? EDIT: I needed it to run the output of g++ in a sandboxed environment where I can't write any file (nothing malicious, I promise).
I don't believe this is possible. The exec(2) system call always requires a filename or absolute path (the filename is always a char*). posix_spawn also has similar requirements for a filename. The closest you could do is pipe the output into a named pipe and try executing from the pipe. That may work, although the...
Is there a way to execute a native binary from a pipe?
1,347,119,015,000
I installed an application [ e.g. fdisk ]. But it required libraries for execution. I am looking for utility/tool which will help me to create a static binary from already installed binaries. So that I can use it anywhere. The only reliable tools that I found is ErmineLight from here , but this one is share-ware. Is...
If fdisk is just an example and your goal is really to make static executables from dynamic executables, try Elf statifier. There's even a comparison with Ermine (by the Ermine vendor, so caveat (non-)emptor). Note that If you have many executables, their combined size is likely to be more than the combined size of t...
Creating Static Binary
1,347,119,015,000
I created a Bash script which echoes "Hello World". I also created a test user, bob, using adduser. Nobody has permission to execute that file as denoted by ls: $ ls -l hello.sh -rw-r--r-- 1 george george 19 Mai 29 13:06 hello.sh As we can see from the above the file's owner is george where he has only read and wri...
In your examples, you are not executing the files, but sourcing them. Executing would be via $ ./hello.sh and for that, execution permission is necessary. In this case a sub-shell is opened in which the commands of the script file are executed. Sourcing, i.e. $ . hello.sh (with a space in between) only reads the fil...
How are users able to execute a file without permission?
1,347,119,015,000
Looks like I cannot run any normal linux binaries if their name ends with .exe, any idea why? $ cp /bin/pwd pwd $ ./pwd /home/premek This is ok. But... $ cp /bin/pwd pwd.exe $ ./pwd.exe bash: ./pwd.exe: No such file or directory $ ls -la pwd.exe -rwxr-xr-x 1 premek premek 39616 May 3 20:27 pwd.exe $ file pwd.exe...
I spent one day on this and of course 1 second after posting this question I remembered something like this existed to register .exe files for wine: $ sudo cat /proc/sys/fs/binfmt_misc/wine enabled interpreter /usr/bin/wine flags: extension .exe and /usr/bin/wine did not exist. I got rid of it using: $ sudo update-...
bash: ./*.exe: No such file or directory with executables named *.exe
1,347,119,015,000
I had a question on a job interview: How can you execute (run) the program with the user user1 without sudo privileges and without access to the root account: $ whoami user1 $ ls -l ~/binary_program -rw-r--r-- 1 root root 126160 Jan 17 18:57 /home/user1/binary_program
Since you have read permission: $ cp ~/binary_program my_binary $ chmod +x my_binary $ ./my_binary Of course this will not auto-magically grant you escalated privileges. You would still be executing that binary as a regular user.
Run a binary owned by root without sudo
1,347,119,015,000
I want to call a python script script.py from the terminal by simply typing script. Is this possible? If so, how? I know I can avoid typing python script.py by adding #!/usr/bin/env python to the top of the script, but I still have to add the suffix .py in order to run the script.
Unix/Linux file systems do not rely on extensions the way windows does. You should not need the .py at the end of a file to run it. You can run the file by either calling it with the interpreter: python ScriptFile Or by marking it executable and defining the interpreter on the first line (e.g. #!/usr/bin/python). If...
Running python script from terminal without .py extension
1,347,119,015,000
I have an sh file that I would like to be able to open from the terminal at any time. I would like to type "studio" into the terminal, and have android studio open I recall using ln -s to do this, but I have forgotten and have already wasted much time searching the web. Also, in which directory is the created symbolic...
The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful. When you type the name of a program, the shell looks for it in the directories lis...
How to use ln -s to create a command line shortcut?
1,347,119,015,000
I have an executable binary; let's call it a.out. I can see the binary contains strings $ strings a.out ... /usr/share/foo .... I need to change the string /usr/share/foo to /usr/share/bar. Can I just replace the string with sed?: sed -i 's@/usr/share/foo@/usr/share/bar@' a.out This looks like a safe thing to do. Wi...
I don't know if your version of sed will be binary-clean or if will choke on what it thinks are really long lines in its input, but barring those issues, editing the string in-place should work. To see whether it does, compare the old and new versions with cmp -l. It should tell you whether or not the only three diffe...
When can I edit strings in an executable binary?
1,347,119,015,000
$ ls -l /usr/bin/sudo -rwsr-xr-x 1 root root 136808 Jul 4 2017 /usr/bin/sudo so sudo is runnable by any user, and any user who runs sudo will have root as the effective user ID of the process because the set-user-id bit of /usr/bin/sudo is set. From https://unix.stackexchange.com/a/11287/674 the most visible diffe...
In its most common configuration, sudo asks for the password of the user running sudo (as you say, the user corresponding to the process’ real user id). The point of sudo is to grant extra privileges to specific users (as determined by the configuration in sudoers), without those users having to provide any other aut...
Which user's password does `sudo` asks for?
1,347,119,015,000
I want to find file types that are executable from the kernel's point of view. As far as I know all the executable files on Linux are ELF files. Thus I tried the following: find * | file | grep ELF However that doesn't work; does anybody have other ideas?
Later edit: only this one does what jan needs: thank you huygens; find . -exec file {} \; | grep -i elf
How to find executable filetypes?
1,347,119,015,000
I'm trying to run a python script, on a headless Raspberry PI using winSCP and get the following error message: Command '"./areadetect_movie_21.py"' failed with return code 127 and error message /usr/bin/env: python : No such file or directory. When I try and run from terminal, I get: : No such file or directory. I ...
From AskUbuntu, answer by Gilles: If you see the error “: No such file or directory” (with nothing before the colon), it means that your shebang line has a carriage return at the end, presumably because it was edited under Windows (which uses CR,LF as a line separator). The CR character causes the cursor to move back...
No such file or directory but I can see it!
1,347,119,015,000
I'm on a kali linux 64 bit. I have created a python script which takes 2 arguments to start. I don't want to type out every time the exact same paths or search in the history of the commands I used in terminal. So I decided to create a simple script which calls the python script with its arguments. #! /bin bash pyt...
You have a space instead of a forward slash here: #! /bin bash Should be: #! /bin/bash or simply #!/bin/bash (the first space is optional).  The shebang (#!) should be followed by the path to an executable, which may be followed by one argument, e.g., #!/usr/bin/env sh In this case /usr/bin/env is the executable;...
Bash Script Permission denied & Bad Interpreter
1,347,119,015,000
Is it possible to check if given program was compiled with GNU gprof instrumentation, i.e. with '-pg' flag passed to both compiler and linker, without running it to check if it would generate a gmon.out file?
You could check for references to function mcount (or possibly _mcount or __mcount according to Implementation of Profiling). This function is necessary for profiling to work, and should be absent for non-profiled binaries. Something like: $ readelf -s someprog | egrep "\s(_+)?mcount\b" && echo "Profiling is on for so...
Detect if an ELF binary was built with gprof instrumentation?
1,347,119,015,000
I have a script that works well when I ssh to the server to execute it myself, but has problems when Hudson, a continuous integration server, runs it. I am automating tests on an embedded linux system (the target). The target is connected to Server A (RHEL 5) via serial and operated over minicom. Server B (FC 12) buil...
The message cannot execute binary file has nothing to do with terminals (I wonder what led you to think that — and I recommend avoiding making such assumptions in a question, as they tend to drown your actual problem in a mess of red herrings). In fact, it's bash's way of expressing ENOEXEC (more commonly expressed as...
./executable: cannot execute binary file
1,347,119,015,000
I've installed the program Motion on one Linux machine (M1) and want the same program on another (M2). There are various builds of this program, and I have forgotten which one I have used, so can I do a straight copy of the user/bin/motion file from M1 and place it in the user/bin/motion of M2? I know where the config...
For moving one program to other computer you have to move: 1) Executable file A simple way to finding commands path is type command. For example: type cal cal is /usr/bin/cal 2) Library dependencies You can find library dependencies with ldd command, But remember if you compiled a program from source the CPU Archit...
Portability of an executable to another Linux machine
1,347,119,015,000
I am trying to start a node.js application with on a low permissions user. All the files I know of are owned by the correct user and have permissions set reasonably well. I'm trying to use a script file to do this. I invoke the script with this command sudo su - nodejs ./start-apps.sh The shell script runs this comm...
The second node-dev is not executable, and the symlink points to that. Although the symlink is executable (symlinks are always 777), it is the mode of the file it points to that counts; note that calling chmod on the link actually changes the mode of the file it points to (symlink permissions never change). So perhap...
Why is permission denied for npm start using node-dev?
1,347,119,015,000
I recently bought a Raspberry Pi. I already have configured it, and I install a cross compiler for arm on my desktop (amd64). I compiled a simple "hello world" program and then I copy it from my desktop to my Pi with scp ./hello [email protected]:~/hello. After login in my Pi I run ls -l hello and I get a normal respo...
If ldd says it is not a dynamic executable, then it was compiled for the wrong target. Obviously you did cross-compile it, as file says is a 32-bit ARM executable. However, there's more than one "ARM" architecture, so possibly your toolchain was configured incorrectly. If you are using crosstool-NG, have a look at th...
“No such file or directory” when executing a cross-compiled program on a Raspberry Pi
1,347,119,015,000
If I compile a program using gcc, and try to execute it from the bash shell, what is the exact sequence of steps followed by bash to execute it ? I know fork(), execve(), loader, dynamic linker (and other things) are involved, but can someone give an exact sequence of steps and some suitable reading reference ? Edit: ...
Well, the exact sequence may vary, as there might be a shell alias or function that first gets expanded/interpreted before the actual program gets executed, and then differences for a qualified filename (/usr/libexec/foo) versus something that will be looked for through all the directories of the PATH environment vari...
How does a shell execute a program?
1,347,119,015,000
Imagine I have a script foo. It should be run once when the user logs in and isn't needed after a successful run. My question: Is it safe to remove the script file from within the script? E.g.: #!/bin/bash # do something ... # if successful rm /path/to/foo exit 0
It it safe to remove the shell file while running it, since file handlers are not affected by (re)moving the corresponding file. For more information, see here.
Is it safe to remove a script file from within that script?
1,347,119,015,000
One thing that puzzles me about desktop Linux, at least, is that just about everything is in my PATH. By everything, I mean every desktop application, including things like gnome-character-map and glchess. These have no command line interfaces to speak of, so I can't think of a case where I would be regularly launchin...
All the commands that a user might want to run are in the PATH. That's what it's for. This includes commands that you run directly, commands that other people run directly, and commands that you or other people run indirectly because they are invoked by other commands. This is not limited to commands run from a termin...
Why do so many programs live in PATH?
1,347,119,015,000
I am trying to run an executable file called i686-elf-gcc in my Kali Linux that I downloaded from this repository. It's a cross-compiler. The problem is that even though the terminal and a script that I wrote can both see that the file exists, when its time to actually execute it I get No such file or directory error...
Typically, the "unable to execute... No such file or directory" means that either the executable binary itself or one of the libraries it needs does not exist. Libraries can also need other libraries themselves. To see a list of libraries required by a specified executable or library, you can use the ldd command: $ ld...
Running executable file: No such file or directory [closed]
1,347,119,015,000
I have a question about overwriting a running executable, or overwriting a shared library (.so) file that's in use by one or more running programs. Back in the day, for the obvious reasons, overwriting a running executable didn't work. There's even a specific errno value, ETXTBSY, that covers this case. But for quite...
It depends on the kernel, and on some kernels it might depend on the type of executable, but I think all modern systems return ETXTBSY (”text file busy“) if you try to open a running executable for writing or to execute a file that's open for writing. Documentation suggests that it's always been the case on BSD, but i...
Overwriting a running executable or .so
1,347,119,015,000
I am making quite some binaries, scripts etc that I want to install easily (using my own rpms). Since I want them accessible for everyone, my intuition would be to put them in /usr/bin; no need to change PATH however; my executables now disappear in a pool of all the others; how can I find back all the executables I...
If you bundle your binaries into your own RPMs then it's trivial to get a list of what they are and where they were installed. Example $ rpm -ql httpd| head -10 /etc/httpd /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/userdir.conf /etc/httpd/conf.d/welcom...
where to put binaries so they are always in path and can be found easily
1,347,119,015,000
I'm using a shared server. On that server different versions of Java are installed: Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode * 1 /usr/...
On Debian and derivates, you should probably use update-java-alternatives. Anyway, all those tools are system related, not user related. If you want to use a different java, simply put those lines in your ~/.profile: JAVA_HOME=/usr/lib/jvm/java-6-sun JRE_HOME=/usr/lib/jvm/java-6-sun/jre PATH=$JAVA_HOME/bin:"$PATH" exp...
update-alternatives just for one user
1,347,119,015,000
I've been using Optware to install packages on my ARM-based NAS for a while - the usual stuff like Transmission, Samba and others. However, I'd been having problems with Transmission hanging not long after starting up. I looked around for a solution for a while and finally discovered that the Optware feed I was usin...
When you fail to execute a file that depends on a “loader”, the error you get may refer to the loader rather than the file you're executing. The loader of a dynamically-linked native executable is the part of the system that's responsible for loading dynamic libraries. It's something like /lib/ld.so or /lib/ld-linux....
"No such file or directory" lies on Optware installed binaries
1,347,119,015,000
Is it possible to get an executable to execute by default? What I mean is this. I have an .sh file, which if I click on twice, it will show me this: If I then click Execute, it does the right thing. Is it possible to get it to Execute without being shown the Execute File dialog box? So simply by double clicking th...
You have to create a "Desktop Entry" like this (not tested): #!/usr/bin/env xdg-open [Desktop Entry] Encoding=UTF-8 Type=Application X-Created-By= name Icon= icon Exec="path_of_file" %u Name=name of program
Default to "Execute" when double-clicking on a shell script in PCManFM
1,347,119,015,000
A minimal ELF executable only requires the ELF header and at least one program header in order to be functional. However, when I run strip on a short executable, it decides not to throw out the section header table or the section strings section, keeping them around although they have no purpose (as far as I know) for...
The documentation for GNU binutils strip alludes to the reason, but is not explicit, mentioning in the description of --only-keep-debug that Note - the section headers of the stripped sections are preserved, including their sizes, but the contents of the section are discarded. The section headers are preserved so tha...
Why doesn't `strip` remove section headers from ELF executables?
1,347,119,015,000
I have seen this question on this site and this prompted me to ask this question . I want to know in Unix speak what is the difference between an executable and a shell script ?
An executable refers to any file with the executable bit set that could be executed (even if there are errors in the actual running of the program). A shell script is a specific type of executable that is intended to be interpreted by a shell using the #! directive to specify an interpreter.
In Unix speak what is the difference between a shell script and an executable?
1,659,734,788,000
I'm using a program called node-webkit, but I can't start the program without specifying the full path to the executable file. Is there any way to associate a command (such as node-webkit) with an executable file on Linux, so that the full path to the file won't need to be specified?
A third option, perhaps least intrusive, is to add an alias in your .bashrc file. This file is a set of options for bash which it reads every time an instance of bash is started. Open your .bashrc file with your file editor, for e.g gedit ~/.bashrc Add the below line to the bottom of your .bashrc file alias node-web...
Create a command for a Linux executable file
1,659,734,788,000
When I'm on my Linux Box I use bash as a shell. Now I wondered how bash handles the execution of an ELF file, that is when I type ./program and program is an ELF file. I grepped the bash-4.3.tar.gz, there does not seem to be some sort of magic number parser to find out if the file is an ELF nor did I find an exec() sy...
Bash knows nothing about ELF. It simply sees that you asked it to run an external program, so it passes the name you gave it as-is to execve(2). Knowledge of things like executable file formats, shebang lines, and execute permissions lives behind that syscall, in the kernel. (It is the same for other shells, though th...
How does bash execute an ELF file?
1,659,734,788,000
I noticed that when I install new application there are a few possible directories where the resulting binary file will be placed. You can install with packaging manager, compile with make, easy_install for Python etc. My $PATH looks as follows: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games A...
There is no hard and fast rule but each distribution has its own logic behind putting things where they do. Generally, /bin is used for system binaries, /usr/bin for default applications that comes with the distribution and /usr/local/bin for things that are installed outside of the normal distribution. You can add a...
Directories with binary files in Linux
1,659,734,788,000
If you go to the VirusTotal link , there is a tab called file info(I think; mine is dutch). You'll see a header called "Authenticode signature block and FileVersionInfo properties" I want to extract the data under the header using Linux cli. Example: Signature verification Signed file, verified signature Signing da...
On Linux there's a tool called osslsigncode which can process Windows Authenticode signatures. Verifying a binary's signature produces output similar to what you show in your example; on a vcredist_x86.exe I have to hand I get: $ osslsigncode verify vcredist_x86.exe Current PE checksum : 004136A1 Calculated PE check...
How can I extract Signatures data from a Windows `exe` file under Linux using cli
1,659,734,788,000
I'm running Arch linux on my laptop, which is kernel 3.12.9 right now. Something has changed about the way the kernel maps in a dynamically-linked executable and I can't figure it out. Here's the example: % /usr/bin/cat /proc/self/maps ... 00400000-0040b000 r-xp 00000000 08:02 1186756 /usr/bin/cat 0060a00...
I finally figured this out. The kernel does map only 2 segments. The third piece is a portion of one of the two loaded by the kernel. The run time linker, the program named in the INTERP pheader, which is /usr/lib/ld-2.24.so for me right now, changes the permissions on the mappings using mprotect() so that there are r...
/proc/self/maps - 3rd mapped piece of file?
1,659,734,788,000
Say I have a file hello: #!/bin/sh echo "Hello World!" Provided the executable bit is set on that file, I can execute it by entering its path on the prompt: $ ./hello Hello World! Is there a more explicit equivalent to the above? Something akin to: $ execute hello I know I can pass hello as an argument to /bin/sh,...
You can use perl: perl hello From perl docs: If the #! line does not contain the word "perl" nor the word "indir", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL ...
Equivalent of executing a file (with shebang line) by entering its path?
1,659,734,788,000
What type of parameter/flag can I use with the unix find command so that I search executables? (if this question is better suited for another stackexchange forum, I welcome you telling me so) p.s. If you know of one, I've been looking for a detailed (non-beginner) tutorial/screencast about grep and/or find.
Portably, the following command looks for regular files that are executable by their owner: find . -perm -700 -type f With GNU find ≥4.3, you can use -executable instead of -perm -700 to look for files that are executable by you.
Find command: Searching for executable files
1,659,734,788,000
I have a process running very long time. I accidentally deleted the binary executable file of the process. Since the process is still running and doesn't get affected, there must be the original binary file in somewhere else.... How can I get recover it? (I use CentOS 7, the running process is written in C++)
It could only be in memory and not recoverable, in which case you'd have to try to recover it from the filesystem using one of those filesystem recovery tools (or from memory, maybe). However! $ cat hamlet.c #include <unistd.h> int main(void) { while (1) { sleep(9999); } } $ gcc -o hamlet hamlet.c $ md5sum hamlet 3055...
How to recover the deleted binary executable file of a running process
1,659,734,788,000
It's a well-known fact that if one wants to execute a script in shell, then the script needs to have execute permissions: $ ls -l total 4 -rw-r--r-- 1 user user 19 Mar 14 01:08 hw $ ./hw bash: ./hw: Permission denied $ /home/user/hw bash: /home/user/hw: Permission denied $ However, it is possible to execute this scri...
Yes, you can use bash /path/to/script, but scripts can have different interpreters. Its possible your script was written to work with ksh, zsh, or maybe even awk or expect. Thus you have to know what interpreter to use to call the script with. By instead making a script with a shebang line (that #!/bin/bash at the top...
reason to add execute permissions to a shell script
1,659,734,788,000
I have a unix executable file located in a directory I generated. I believe I need to get this directory in my $PATH so that the unix executable is executable, but the documentation for the source code says that I need to edit my shell configuration file to add $home/meme/bin to my shell's path.
If you want to be able to execute a program by typing its name on the command line, the program executable must be in one of the directories listed in the PATH environment variable. You can see the current value of the variable like this ($ is your prompt, and the value below is an example): $ echo $PATH /home/drbunse...
Problem with $PATH and executable file
1,659,734,788,000
Currently setting up xpra, which wants to run an X instance as non-root using the dummy driver, but the system Xorg binary is SUID. Since the system auto-updates, I would prefer not making and maintaining a non-SUID copy of the binary. I'm also trying to avoid using a hack like copy-execute-delete, e.g. in the tmp d...
If X is dynamically linked, you could call the dynamic linker like: /lib/ld.so /path/to/X (adapt ld.so to your system (like /lib/ld-linux.so.2). Example: $ /lib64/ld-linux-x86-64.so.2 /bin/ping localhost ping: icmp open socket: Operation not permitted
Running setuid binary temporarily without setuid?
1,659,734,788,000
I have seen many tutorials saying that the bin directory is used to store binary files, meaning there is only 0 and 1 in the files in that directory. However, in many cases, I see files in bin that are not only 0 and 1. For example, the django-admin.py under the xx/bin/ directory: #!/usr/bin/env python from django.cor...
No, a bin directory is not for storing only binary files. It's for keeping executable files, primarily. Historically, before scripts written in various scripting languages became more common, bin directories would have contained mainly binary (compiled or assembled) non-text files, as opposed to source code. The main...
Is the bin/ directory for storing binary files?
1,659,734,788,000
When you run ./myscript.sh is that considered as "access" time? I need to know the last time a script was run, but I'm not sure if this counts as mtime, ctime or atime (differences described here).
As explained in the answer you linked to, that depends on your settings. In principle, atime will change each time a file is read and in order to run a script, you need to read it. So yes, normally, the atime will change each time the script is executed. This is easily demonstrated by checking the current atime, runni...
Check last time .sh file used
1,659,734,788,000
One thing that has been puzzling me for some time is this: % which halt /sbin/halt % file /sbin/halt /sbin/halt: symbolic link to `reboot' However, executing sudo halt does, of course, not reboot the system. Why is that? There are several other programs working that way, for example pdflatex.
Every program can see the full command line that was used to run it (except for wildcards and variables, which the shell expands). In a C program, the command line is stored in argv, which is short for argument vector. The progam's name is the first element of argv, i.e. argv[0]. Clearly in the case of halt and reboot...
Why do some symbolic links affect program behavior?
1,659,734,788,000
I'm trying to understand Linux file system, and one of the question is: 1- Why there are multiple folders for executable files: /usr/bin, /usr/sbin/ and /usr/local/bin? Is there any differences between them ? 2- If I have an executable file and I want to add it to my system, which of the third latter locations is the...
Run man hier from the command line to get the answer to your first question. It depends. See /usr/bin vs /usr/local/bin on Linux
Why there are multiple folders for executable files in Linux? [duplicate]
1,659,734,788,000
I have downloaded this script named, pyAES.py and put it in a folder name codes, inside a Desktop directory of my Linux, According to this example, http://brandon.sternefamily.net/2007/06/aes-tutorial-python-implementation/ When I type, ./pyAES.py -e testfile.txt -o testfile_encrypted.txt the file pyAES.py should be...
It seems you have a badly-written shebang line. From the error you're getting: -bash: /usr/bin/pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory I'd say you should set the first line of /usr/bin/pyAES.py to #!/correct/path/to/python where the /correct/path/to/python can be found from the output ...
Running python script from Linux Terminal
1,659,734,788,000
I hit again on this strange behaviour of the system. I'm running Debian 6.0.6 and had quite some troubles executing a script directly from CD/DVD. Finally I had to use: sh /media/cdrom/command to run it. What is the big deal of having to resort to sh?! What if the script relies on bash features? Really annoying and n...
Filesystems are often mounted noexec,nosuid by default to boost the security a bit. Hence even though you see the executable bit on the file set, kernel will refuse to run it. By calling it in the form of interpreter path/to/script you are requesting the system to run interpreter, which in turn receives path/to/script...
Why do I have to use sh to execute scripts from CD/DVD media?
1,659,734,788,000
I found a command rename.ul on my Ubuntu machine. It comes from util-linux package. It is odd for me because I rarely see executables with extension. In addition, it seems unnecessary because the file is compiled. Are there any historical or technical reasons on it? I'm also confused because I could not find file f...
The extension is to avoid conflict with the multitude of rename commands otherwise available on Debian. This change was made in 2007 in response to Debian bug #439647: /usr/bin/rename is managed by the alternatives system (with Perl's version the default). util-linux 2.13~rc3-8 installs its own binary there, inst...
Why /usr/bin/rename.ul has an extension?
1,659,734,788,000
I have a directory test with three files, ls -l test: total 8 -rw-r--r-- 1 mb mb 16 Jul 25 11:12 regular_file -rwxr-xr-x 1 mb mb 19 Jul 25 11:02 script.sh lrwxrwxrwx 1 mb mb 12 Jul 25 11:14 symlink -> regular_file It contains a regular file, a symbolic link, and an executable script. After archiving this directory wi...
This seems to be a limitation of 7-Zip, judging from these bug reports: #1302 .tar archives fail to extract properly #1188 symlinks in tar archives are extracted to 0 byte files For now, I'll keep using tar -xzf test.tgz to extract the files.
Preserve file permissions and symlinks in archive with 7-Zip
1,659,734,788,000
Many guides on the internet recommend setting the nosuid and noexec options, for example on the /tmp mount point. But doesn't noexec imply nosuid? What cannot get executed cannot make use of the suid bit, right?
Thanks for the link LJKims, it helps me to answer my own question. I forgot that the suid/sgid bit can also be set for directories. According to the GNU coreutils documentation files and directories that are created in a suid-directory inherit the owner of the directory (sgid-directories inherit the group obviously). ...
Does the noexec mount option imply nosuid?
1,659,734,788,000
I know how to monitor a process. Commands like top and so forth can monitor the CPU time and memory usage for a given process instance. But say I expect a given executable to be run several times in the next hour, and I want to measure how many times it is run and the CPU time it has consumed. What's a command for tha...
You could do something like: mv my-executable my-executable.bin And create my-executable as a wrapper script that does: #! /bin/bash - { time "$0.bin" "$@" 2>&3 3>&-; } 3>&2 2>> /tmp/times.log The script could add more information to the log like the time it was started, by whom, the arguments it was passed... BSD p...
How to monitor all executions of an executable over a time period
1,659,734,788,000
I would like to use install command in order to create a new executable file with pre-populated content (e.g. with single pwd command in it). So I've extended this example which creates a new empty executable file: install -b -m 755 /dev/null newfile into this one: install -m755 <(echo pwd) newfile or: echo pwd | in...
The BSD install found on OpenBSD systems has this piece of code in it (from src/usr.bin/xinstall/xinstall.c): if (!S_ISREG(to_sb.st_mode)) errc(1, EFTYPE, "%s", to_name); This emits the error install: /dev/fd/4: Inappropriate file type or format when it's discovered that /dev/df/4 is not a regular file. (There's...
Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?
1,659,734,788,000
Is it possible to have, say, one machine with software installed and call that software from another machine? I thought this would be called an "application server" but by googling I find things that are not exactly what I want. My scenario is basically the following: I have a computer at home with Ubuntu and a bunch ...
Yes it is possible, but there are multiple steps involved: You must be able to reach your home computer running Linux from the internet. This means opening up port 22 (ssh) or your router at home, or a higher port if your provider blocks incoming access on ports below 1024. Then install openssh-server (and make it li...
How can one run a program installed in one machine from another machine?
1,659,734,788,000
I have a number of files showing up green when I run ls. I understand these are executables, and I understand that one can make a file executable with chmod. But they are .csv and .pdf files. I don't understand how one could 'execute' a comma-separated text file or a PDF. So: How can they actually be 'executable'? An...
This is just a question of permissions. If a file has execute permissions, that just means users are allowed to execute it. Whether they will be successful is another matter. In order for a file to be executed, the user executing it must have the right to do so and the file needs to be a valid executable. The permissi...
Executable common files (*.pdf, etc.)
1,659,734,788,000
I notice that with bash scripts, some people use a different shebang to the one that I'm used to putting at the top of my own. Can someone simplify the difference between these two? I use the #!/bin/bash one all the time. #!/bin/bash #!/usr/bin/env bash
The #!/usr/bin/env bash results in the script using whatever bash is found first in $PATH. While it is common for bash to be located at /bin/bash. There are cases where it is not (different operating systems). Another potential use is when there are multiple bash shells installed (newer version at an alternate locatio...
What is the difference in these two bash environments?